11import type { Types } from '@graphql-codegen/plugin-helpers' ;
2- import type { AsyncDataOptions } from 'nuxt/app' ;
32import type { Import } from 'unimport' ;
43
54import { generate } from '@graphql-codegen/cli' ;
@@ -9,11 +8,6 @@ import { ofetch } from 'ofetch';
98
109import { useGraphQLMeta } from './runtime/composables/use-graphql-meta' ;
1110
12- interface GraphQLOptions {
13- asyncDataOptions ?: AsyncDataOptions ;
14- headers ?: Record < string , string > ;
15- log ?: boolean ;
16- }
1711
1812export type GraphQLMeta = ReturnType < typeof useGraphQLMeta > ;
1913
@@ -97,6 +91,7 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
9791 template . push ( 'import type { AsyncData, AsyncDataOptions } from \'nuxt/app\';\n' ) ;
9892 template . push ( 'import type { ReturnTypeOfSubscription } from \'#base-interfaces/return-type-of-subscription.interface\';\n' ) ;
9993 template . push ( 'import type { GraphqlError } from \'#base-interfaces/graphql-error.interface\';\n' ) ;
94+ template . push ( 'import type { IGraphQLOptions } from \'#base-interfaces/graphql-options.interface\';\n' ) ;
10095
10196 if ( methods ?. query ) {
10297 for ( const query of methods . query ) {
@@ -108,13 +103,13 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
108103 template . push (
109104 `export const use${ capitalizeFirstLetter ( query ) } Query = (${
110105 types . argType ? 'variables: { ' + types . argType + ' },' : ''
111- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: GraphQLOptions ): Promise<{data: ${ types . returnType } ; error: GraphqlError | null}> => gqlQuery<${ types . returnType } >('${ query } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
106+ } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: IGraphQLOptions ): Promise<{data: ${ types . returnType } ; error: GraphqlError | null}> => gqlQuery<${ types . returnType } >('${ query } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
112107 ) ;
113108
114109 template . push (
115110 `export const useAsync${ capitalizeFirstLetter ( query ) } Query = (${
116111 types . argType ? 'variables: { ' + types . argType + ' },' : ''
117- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: GraphQLOptions ): Promise<AsyncData<${ types . returnType } , Error>> => gqlAsyncQuery<${ types . returnType } >('${ query } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
112+ } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: IGraphQLOptions ): Promise<AsyncData<${ types . returnType } , Error>> => gqlAsyncQuery<${ types . returnType } >('${ query } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
118113 ) ;
119114 }
120115 }
@@ -129,7 +124,7 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
129124 template . push (
130125 `export const use${ capitalizeFirstLetter ( mutation ) } Mutation = (${
131126 types . argType ? 'variables: { ' + types . argType + ' },' : ''
132- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: GraphQLOptions ): Promise<{data: ${ types . returnType } ; error: GraphqlError}> => gqlMutation<${ types . returnType } >('${ mutation } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
127+ } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: IGraphQLOptions ): Promise<{data: ${ types . returnType } ; error: GraphqlError}> => gqlMutation<${ types . returnType } >('${ mutation } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
133128 ) ;
134129 }
135130 }
@@ -144,7 +139,7 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
144139 template . push (
145140 `export const use${ capitalizeFirstLetter ( subscription ) } Subscription = (${
146141 types . argType ? 'variables: { ' + types . argType + ' },' : ''
147- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: GraphQLOptions ): Promise<ReturnTypeOfSubscription<${ types . returnType } >> => gqlSubscription<${ types . returnType } >('${ subscription } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
142+ } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options?: IGraphQLOptions ): Promise<ReturnTypeOfSubscription<${ types . returnType } >> => gqlSubscription<${ types . returnType } >('${ subscription } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , ...options})`,
148143 ) ;
149144 }
150145 }
0 commit comments