Skip to content

Add more tests to cover useMutation generated-flow-types validations #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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