From fd0b76fb9f5b7ff1e71ac0a0a6e548402be6649a Mon Sep 17 00:00:00 2001 From: Lee Staples Date: Fri, 29 Nov 2024 15:42:49 +0000 Subject: [PATCH 1/2] Add more tests to cover useMutation generated-flow-types validations --- test/generated-typescript-types.js | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/generated-typescript-types.js b/test/generated-typescript-types.js index ce1e346..aa1137b 100644 --- a/test/generated-typescript-types.js +++ b/test/generated-typescript-types.js @@ -228,6 +228,30 @@ ruleTester.run( user: graphql\`fragment MyComponent_user on User {id}\`, }); ` + }, + { + code: ` + import type {TestMutation} from 'TestMutation.graphql'; + const mutation = useMutation(graphql\`mutation TestMutation { testMutation { test } }\`) + ` + }, + { + code: ` + import type {TestMutation} from 'TestMutation.graphql'; + const mutation = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`) + ` + }, + { + code: ` + import type {TestMutation} from 'TestMutation.graphql'; + const [commit, inFlight] = useMutation(graphql\`mutation TestMutation { testMutation { test } }\`) + ` + }, + { + code: ` + import type {TestMutation} from 'TestMutation.graphql'; + const [commit, inFlight] = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`) + ` } ], invalid: [ @@ -1561,6 +1585,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(...)', + line: 2 + } + ], + output: ` +import type {TestMutation} from './__generated__/TestMutation.graphql' + const mutation = useMutation(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(...)', + line: 2 + } + ], + output: ` +import type {TestMutation} from './__generated__/TestMutation.graphql' + const mutation = useMutation(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(...)', + line: 2 + } + ], + output: ` +import type {TestMutation} from './__generated__/TestMutation.graphql' + const [commit, inFlight] = useMutation(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(...)', + line: 2 + } + ], + output: ` +import type {TestMutation} from './__generated__/TestMutation.graphql' + const [commit, inFlight] = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`);` } ] } From f4421012eb3637ccb456f3e412bd85f250b89da6 Mon Sep 17 00:00:00 2001 From: Lee Staples Date: Tue, 3 Dec 2024 17:40:28 +0000 Subject: [PATCH 2/2] Add a couple more tests --- test/generated-typescript-types.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/generated-typescript-types.js b/test/generated-typescript-types.js index aa1137b..7bec23f 100644 --- a/test/generated-typescript-types.js +++ b/test/generated-typescript-types.js @@ -241,6 +241,18 @@ ruleTester.run( const mutation = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`) ` }, + { + code: ` + import type {TestMutation} from './__generated__/TestMutation.graphql'; + const mutation = useMutation(graphql\`mutation TestMutation { testMutation { test } }\`) + ` + }, + { + code: ` + import type {TestMutation} from './__generated__/TestMutation.graphql'; + const mutation = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`) + ` + }, { code: ` import type {TestMutation} from 'TestMutation.graphql'; @@ -252,6 +264,18 @@ ruleTester.run( import type {TestMutation} from 'TestMutation.graphql'; const [commit, inFlight] = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`) ` + }, + { + code: ` + import type {TestMutation} from './__generated__/TestMutation.graphql'; + const [commit, inFlight] = useMutation(graphql\`mutation TestMutation { testMutation { test } }\`) + ` + }, + { + code: ` + import type {TestMutation} from './__generated__/TestMutation.graphql'; + const [commit, inFlight] = useMutation(graphql\`mutation TestMutation($foo: String!) { testMutation(foo: $foo) { test } }\`) + ` } ], invalid: [