Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions test/generated-typescript-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,54 @@ ruleTester.run(
user: graphql\`fragment MyComponent_user on User {id}\`,
});
`
},
{
code: `
import type {TestMutation} from 'TestMutation.graphql';
const mutation = useMutation<TestMutation>(graphql\`mutation TestMutation { testMutation { test } }\`)
`
},
{
code: `
import type {TestMutation} from 'TestMutation.graphql';
const mutation = useMutation<TestMutation>(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`)
`
},
{
code: `
import type {TestMutation} from './__generated__/TestMutation.graphql';
const mutation = useMutation<TestMutation>(graphql\`mutation TestMutation { testMutation { test } }\`)
`
},
{
code: `
import type {TestMutation} from './__generated__/TestMutation.graphql';
const mutation = useMutation<TestMutation>(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`)
`
},
{
code: `
import type {TestMutation} from 'TestMutation.graphql';
const [commit, inFlight] = useMutation<TestMutation>(graphql\`mutation TestMutation { testMutation { test } }\`)
`
},
{
code: `
import type {TestMutation} from 'TestMutation.graphql';
const [commit, inFlight] = useMutation<TestMutation>(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`)
`
},
{
code: `
import type {TestMutation} from './__generated__/TestMutation.graphql';
const [commit, inFlight] = useMutation<TestMutation>(graphql\`mutation TestMutation { testMutation { test } }\`)
`
},
{
code: `
import type {TestMutation} from './__generated__/TestMutation.graphql';
const [commit, inFlight] = useMutation<TestMutation>(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`)
`
}
],
invalid: [
Expand Down Expand Up @@ -1561,6 +1609,66 @@ import type {FooSubscription} from './__generated__/FooSubscription.graphql'
column: 15
}
]
},
{
code: `
const mutation = useMutation(graphql\`mutation TestMutation { testMutation { test } }\`);`,
options: DEFAULT_OPTIONS,
errors: [
{
message:
'The `useMutation` hook should be used with an explicit generated Typescript type, e.g.: useMutation<TestMutation>(...)',
line: 2
}
],
output: `
import type {TestMutation} from './__generated__/TestMutation.graphql'
const mutation = useMutation<TestMutation>(graphql\`mutation TestMutation { testMutation { test } }\`);`
},
{
code: `
const mutation = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`);`,
options: DEFAULT_OPTIONS,
errors: [
{
message:
'The `useMutation` hook should be used with an explicit generated Typescript type, e.g.: useMutation<TestMutation>(...)',
line: 2
}
],
output: `
import type {TestMutation} from './__generated__/TestMutation.graphql'
const mutation = useMutation<TestMutation>(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`);`
},
{
code: `
const [commit, inFlight] = useMutation(graphql\`mutation TestMutation { testMutation { test } }\`);`,
options: DEFAULT_OPTIONS,
errors: [
{
message:
'The `useMutation` hook should be used with an explicit generated Typescript type, e.g.: useMutation<TestMutation>(...)',
line: 2
}
],
output: `
import type {TestMutation} from './__generated__/TestMutation.graphql'
const [commit, inFlight] = useMutation<TestMutation>(graphql\`mutation TestMutation { testMutation { test } }\`);`
},
{
code: `
const [commit, inFlight] = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`);`,
options: DEFAULT_OPTIONS,
errors: [
{
message:
'The `useMutation` hook should be used with an explicit generated Typescript type, e.g.: useMutation<TestMutation>(...)',
line: 2
}
],
output: `
import type {TestMutation} from './__generated__/TestMutation.graphql'
const [commit, inFlight] = useMutation<TestMutation>(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`);`
}
]
}
Expand Down