File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -564,6 +564,24 @@ module.exports = {
564564 } ) ;
565565 } ,
566566
567+ /**
568+ * Find useMutation() calls without type arguments.
569+ */
570+ 'CallExpression[callee.name=useMutation]:not([typeArguments])' ( node ) {
571+ const queryName = getDefinitionName ( node . arguments [ 0 ] ) ;
572+ context . report ( {
573+ node,
574+ message : `The \`useMutation\` hook should be used with an explicit generated Flow type, e.g.: useMutation<{{queryName}}>(...)` ,
575+ data : {
576+ queryName : queryName
577+ } ,
578+ fix :
579+ queryName != null && options . fix
580+ ? createTypeImportFixer ( node , queryName , queryName )
581+ : null
582+ } ) ;
583+ } ,
584+
567585 /**
568586 * Find usePaginationFragment() calls without type arguments.
569587 */
Original file line number Diff line number Diff line change @@ -901,6 +901,21 @@ import type {FooQuery} from './__generated__/FooQuery.graphql'
901901 ] ,
902902 output : null
903903 } ,
904+ {
905+ code : `\nconst mutation = graphql\`mutation FooMutation { id }\`;\nconst [commit] = useMutation(mutation);` ,
906+ options : DEFAULT_OPTIONS ,
907+ errors : [
908+ {
909+ message :
910+ 'The `useMutation` hook should be used with an explicit generated Flow type, e.g.: useMutation<FooMutation>(...)' ,
911+ line : 3
912+ }
913+ ] ,
914+ output : `
915+ import type {FooMutation} from './__generated__/FooMutation.graphql'
916+ const mutation = graphql\`mutation FooMutation { id }\`;
917+ const [commit] = useMutation<FooMutation>(mutation);`
918+ } ,
904919 {
905920 code : `\ncommitMutation(environemnt, {mutation: graphql\`mutation FooMutation { id }\`})` ,
906921 errors : [
You can’t perform that action at this time.
0 commit comments