@@ -8,6 +8,7 @@ import { ofetch } from 'ofetch';
88
99import { useGraphQLMeta } from './runtime/composables/use-graphql-meta' ;
1010
11+
1112export type GraphQLMeta = ReturnType < typeof useGraphQLMeta > ;
1213
1314const { loadSchema } = require ( '@graphql-tools/load' ) ;
@@ -90,6 +91,7 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
9091 template . push ( 'import type { AsyncData, AsyncDataOptions } from \'nuxt/app\';\n' ) ;
9192 template . push ( 'import type { ReturnTypeOfSubscription } from \'#base-interfaces/return-type-of-subscription.interface\';\n' ) ;
9293 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' ) ;
9395
9496 if ( methods ?. query ) {
9597 for ( const query of methods . query ) {
@@ -101,13 +103,13 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
101103 template . push (
102104 `export const use${ capitalizeFirstLetter ( query ) } Query = (${
103105 types . argType ? 'variables: { ' + types . argType + ' },' : ''
104- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } log ?: boolean ): Promise<{data: ${ types . returnType } ; error: GraphqlError | null}> => gqlQuery<${ types . returnType } >('${ query } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , log })`,
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 })`,
105107 ) ;
106108
107109 template . push (
108110 `export const useAsync${ capitalizeFirstLetter ( query ) } Query = (${
109111 types . argType ? 'variables: { ' + types . argType + ' },' : ''
110- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } log ?: boolean, asyncDataOptions?: AsyncDataOptions ): Promise<AsyncData<${ types . returnType } , Error>> => gqlAsyncQuery<${ types . returnType } >('${ query } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , asyncDataOptions, log })`,
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 })`,
111113 ) ;
112114 }
113115 }
@@ -122,7 +124,7 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
122124 template . push (
123125 `export const use${ capitalizeFirstLetter ( mutation ) } Mutation = (${
124126 types . argType ? 'variables: { ' + types . argType + ' },' : ''
125- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } log ?: boolean ): Promise<{data: ${ types . returnType } ; error: GraphqlError}> => gqlMutation<${ types . returnType } >('${ mutation } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , log })`,
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 })`,
126128 ) ;
127129 }
128130 }
@@ -137,7 +139,7 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
137139 template . push (
138140 `export const use${ capitalizeFirstLetter ( subscription ) } Subscription = (${
139141 types . argType ? 'variables: { ' + types . argType + ' },' : ''
140- } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } log ?: boolean ): Promise<ReturnTypeOfSubscription<${ types . returnType } >> => gqlSubscription<${ types . returnType } >('${ subscription } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , log })`,
142+ } ${ returnTypeIsDefaultType ? '' : `fields?: InputFields<${ inputFieldsType } >[] | null,` } options ?: IGraphQLOptions ): Promise<ReturnTypeOfSubscription<${ types . returnType } >> => gqlSubscription<${ types . returnType } >('${ subscription } ', {${ types . argType ? 'variables,' : '' } ${ returnTypeIsDefaultType ? 'fields: null' : 'fields' } , options })`,
141143 ) ;
142144 }
143145 }
0 commit comments