@@ -21,6 +21,7 @@ import j, {
2121 TSTypeParameterInstantiation ,
2222 TSQualifiedName ,
2323 TSTypeAliasDeclaration ,
24+ CallExpression ,
2425} from 'jscodeshift'
2526import findImports from 'jscodeshift-find-imports'
2627import addImports from 'jscodeshift-add-imports'
@@ -178,7 +179,7 @@ export default function graphqlTypegenCore(
178179 throw new Error ( 'invalid typeAnnotation' )
179180 }
180181
181- function makeFunctionTypeArguments (
182+ function makeFunctionTypeParameterInstantiation (
182183 data : TypeAlias | TSTypeAliasDeclaration ,
183184 variables ?: TypeAlias | TSTypeAliasDeclaration | null | undefined
184185 ) : TypeParameterInstantiation | TSTypeParameterInstantiation {
@@ -553,6 +554,14 @@ export default function graphqlTypegenCore(
553554 } )
554555 }
555556
557+ const setTypeParameters = (
558+ node : CallExpression ,
559+ params : TypeParameterInstantiation | TSTypeParameterInstantiation
560+ ) => {
561+ if ( isTS ) ( node as any ) . typeParameters = params
562+ else ( node as any ) . typeArguments = params
563+ }
564+
556565 //////////////////////////////////////////////////
557566 // Add types to useQuery hooks
558567
@@ -572,9 +581,9 @@ export default function graphqlTypegenCore(
572581 const { data, variables } = onlyValue ( generatedTypes . query ) || { }
573582 if ( ! data || path . node . init ?. type !== 'CallExpression' ) return
574583 if ( useFunctionTypeArguments ) {
575- ; ( path . node . init as any ) . typeArguments = makeFunctionTypeArguments (
576- data ,
577- variables
584+ setTypeParameters (
585+ path . node . init ,
586+ makeFunctionTypeParameterInstantiation ( data , variables )
578587 )
579588 } else {
580589 if (
@@ -636,9 +645,9 @@ export default function graphqlTypegenCore(
636645 node : { id } ,
637646 } = path
638647 if ( useFunctionTypeArguments ) {
639- ; ( path . node . init as any ) . typeArguments = makeFunctionTypeArguments (
640- data ,
641- variables
648+ setTypeParameters (
649+ path . node . init ,
650+ makeFunctionTypeParameterInstantiation ( data , variables )
642651 )
643652 } else {
644653 if ( ! mutationFunction ) return
@@ -684,11 +693,11 @@ export default function graphqlTypegenCore(
684693 . forEach ( ( path : ASTPath < VariableDeclarator > ) : void => {
685694 const { data, variables } =
686695 onlyValue ( generatedTypes . subscription ) || { }
687- if ( ! data ) return
696+ if ( ! data || path . node . init ?. type !== 'CallExpression' ) return
688697 if ( useFunctionTypeArguments ) {
689- ; ( path . node . init as any ) . typeArguments = makeFunctionTypeArguments (
690- data ,
691- variables
698+ setTypeParameters (
699+ path . node . init ,
700+ makeFunctionTypeParameterInstantiation ( data , variables )
692701 )
693702 } else {
694703 if (
0 commit comments