@graphql-codegen/typescript-react-query 3.5.8 → 3.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +34 -28
- package/index.mjs +34 -28
- package/package.json +1 -1
- package/visitor.d.ts +2 -1
package/index.js
CHANGED
|
@@ -65,8 +65,8 @@ class CustomMapperFetcher {
|
|
|
65
65
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
66
66
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
67
67
|
const hookConfig = this.visitor.queryMethodMap;
|
|
68
|
-
this.visitor.
|
|
69
|
-
this.visitor.
|
|
68
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
69
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
70
70
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
71
71
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
72
72
|
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
|
|
@@ -90,8 +90,8 @@ class CustomMapperFetcher {
|
|
|
90
90
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
91
91
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
92
92
|
const hookConfig = this.visitor.queryMethodMap;
|
|
93
|
-
this.visitor.
|
|
94
|
-
this.visitor.
|
|
93
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
94
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
95
95
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
96
96
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
97
97
|
const impl = this._isReactHook
|
|
@@ -113,8 +113,8 @@ class CustomMapperFetcher {
|
|
|
113
113
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
114
114
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
115
115
|
const hookConfig = this.visitor.queryMethodMap;
|
|
116
|
-
this.visitor.
|
|
117
|
-
this.visitor.
|
|
116
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
117
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
118
118
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
119
119
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
120
120
|
const impl = this._isReactHook
|
|
@@ -171,8 +171,8 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
171
171
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
172
172
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
173
173
|
const hookConfig = this.visitor.queryMethodMap;
|
|
174
|
-
this.visitor.
|
|
175
|
-
this.visitor.
|
|
174
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
175
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
176
176
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
177
177
|
return `export const useInfinite${operationName} = <
|
|
178
178
|
TData = ${operationResultType},
|
|
@@ -192,8 +192,8 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
192
192
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
193
193
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
194
194
|
const hookConfig = this.visitor.queryMethodMap;
|
|
195
|
-
this.visitor.
|
|
196
|
-
this.visitor.
|
|
195
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
196
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
197
197
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
198
198
|
return `export const use${operationName} = <
|
|
199
199
|
TData = ${operationResultType},
|
|
@@ -212,8 +212,8 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
212
212
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
213
213
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
214
214
|
const hookConfig = this.visitor.queryMethodMap;
|
|
215
|
-
this.visitor.
|
|
216
|
-
this.visitor.
|
|
215
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
216
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
217
217
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
218
218
|
return `export const use${operationName} = <
|
|
219
219
|
TError = ${this.visitor.config.errorType},
|
|
@@ -249,8 +249,8 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
249
249
|
const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
|
|
250
250
|
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
|
|
251
251
|
const hookConfig = this.visitor.queryMethodMap;
|
|
252
|
-
this.visitor.
|
|
253
|
-
this.visitor.
|
|
252
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
253
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
254
254
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
255
255
|
return `export const useInfinite${operationName} = <
|
|
256
256
|
TData = ${operationResultType},
|
|
@@ -274,8 +274,8 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
274
274
|
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
|
|
275
275
|
this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
|
|
276
276
|
const hookConfig = this.visitor.queryMethodMap;
|
|
277
|
-
this.visitor.
|
|
278
|
-
this.visitor.
|
|
277
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
278
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
279
279
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
280
280
|
return `export const use${operationName} = <
|
|
281
281
|
TData = ${operationResultType},
|
|
@@ -294,10 +294,11 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
294
294
|
}
|
|
295
295
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
296
296
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
297
|
-
this.visitor.
|
|
297
|
+
const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
|
|
298
|
+
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
|
|
298
299
|
const hookConfig = this.visitor.queryMethodMap;
|
|
299
|
-
this.visitor.
|
|
300
|
-
this.visitor.
|
|
300
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
301
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
301
302
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
302
303
|
return `export const use${operationName} = <
|
|
303
304
|
TError = ${this.visitor.config.errorType},
|
|
@@ -367,8 +368,8 @@ ${this.getFetchParams()}
|
|
|
367
368
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
368
369
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
369
370
|
const hookConfig = this.visitor.queryMethodMap;
|
|
370
|
-
this.visitor.
|
|
371
|
-
this.visitor.
|
|
371
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
372
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
372
373
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
373
374
|
return `export const useInfinite${operationName} = <
|
|
374
375
|
TData = ${operationResultType},
|
|
@@ -387,8 +388,8 @@ ${this.getFetchParams()}
|
|
|
387
388
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
388
389
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
389
390
|
const hookConfig = this.visitor.queryMethodMap;
|
|
390
|
-
this.visitor.
|
|
391
|
-
this.visitor.
|
|
391
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
392
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
392
393
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
393
394
|
return `export const use${operationName} = <
|
|
394
395
|
TData = ${operationResultType},
|
|
@@ -406,8 +407,8 @@ ${this.getFetchParams()}
|
|
|
406
407
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
407
408
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
408
409
|
const hookConfig = this.visitor.queryMethodMap;
|
|
409
|
-
this.visitor.
|
|
410
|
-
this.visitor.
|
|
410
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
411
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
411
412
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
412
413
|
return `export const use${operationName} = <
|
|
413
414
|
TError = ${this.visitor.config.errorType},
|
|
@@ -437,7 +438,8 @@ class ReactQueryVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
437
438
|
addInfiniteQuery: visitorPluginCommon.getConfigValue(rawConfig.addInfiniteQuery, false),
|
|
438
439
|
});
|
|
439
440
|
this.rawConfig = rawConfig;
|
|
440
|
-
this.
|
|
441
|
+
this.reactQueryHookIdentifiersInUse = new Set();
|
|
442
|
+
this.reactQueryOptionsIdentifiersInUse = new Set();
|
|
441
443
|
this.queryMethodMap = {
|
|
442
444
|
infiniteQuery: {
|
|
443
445
|
hook: 'useInfiniteQuery',
|
|
@@ -481,9 +483,13 @@ class ReactQueryVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
481
483
|
return baseImports;
|
|
482
484
|
}
|
|
483
485
|
if (this.config.addInfiniteQuery) {
|
|
484
|
-
this.
|
|
486
|
+
this.reactQueryOptionsIdentifiersInUse.add('QueryFunctionContext');
|
|
485
487
|
}
|
|
486
|
-
|
|
488
|
+
const hookAndTypeImports = [
|
|
489
|
+
...Array.from(this.reactQueryHookIdentifiersInUse),
|
|
490
|
+
...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
|
|
491
|
+
];
|
|
492
|
+
return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from 'react-query';`];
|
|
487
493
|
}
|
|
488
494
|
getFetcherImplementation() {
|
|
489
495
|
return this.fetcher.generateFetcherImplementaion();
|
package/index.mjs
CHANGED
|
@@ -59,8 +59,8 @@ class CustomMapperFetcher {
|
|
|
59
59
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
60
60
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
61
61
|
const hookConfig = this.visitor.queryMethodMap;
|
|
62
|
-
this.visitor.
|
|
63
|
-
this.visitor.
|
|
62
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
63
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
64
64
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
65
65
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
66
66
|
const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
|
|
@@ -84,8 +84,8 @@ class CustomMapperFetcher {
|
|
|
84
84
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
85
85
|
const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
86
86
|
const hookConfig = this.visitor.queryMethodMap;
|
|
87
|
-
this.visitor.
|
|
88
|
-
this.visitor.
|
|
87
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
88
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
89
89
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
90
90
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
91
91
|
const impl = this._isReactHook
|
|
@@ -107,8 +107,8 @@ class CustomMapperFetcher {
|
|
|
107
107
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
108
108
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
109
109
|
const hookConfig = this.visitor.queryMethodMap;
|
|
110
|
-
this.visitor.
|
|
111
|
-
this.visitor.
|
|
110
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
111
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
112
112
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
113
113
|
const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
|
|
114
114
|
const impl = this._isReactHook
|
|
@@ -165,8 +165,8 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
165
165
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
166
166
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
167
167
|
const hookConfig = this.visitor.queryMethodMap;
|
|
168
|
-
this.visitor.
|
|
169
|
-
this.visitor.
|
|
168
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
169
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
170
170
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
171
171
|
return `export const useInfinite${operationName} = <
|
|
172
172
|
TData = ${operationResultType},
|
|
@@ -186,8 +186,8 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
186
186
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
187
187
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
188
188
|
const hookConfig = this.visitor.queryMethodMap;
|
|
189
|
-
this.visitor.
|
|
190
|
-
this.visitor.
|
|
189
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
190
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
191
191
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
192
192
|
return `export const use${operationName} = <
|
|
193
193
|
TData = ${operationResultType},
|
|
@@ -206,8 +206,8 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
|
|
|
206
206
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
207
207
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
208
208
|
const hookConfig = this.visitor.queryMethodMap;
|
|
209
|
-
this.visitor.
|
|
210
|
-
this.visitor.
|
|
209
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
210
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
211
211
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
212
212
|
return `export const use${operationName} = <
|
|
213
213
|
TError = ${this.visitor.config.errorType},
|
|
@@ -243,8 +243,8 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
243
243
|
const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
|
|
244
244
|
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
|
|
245
245
|
const hookConfig = this.visitor.queryMethodMap;
|
|
246
|
-
this.visitor.
|
|
247
|
-
this.visitor.
|
|
246
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
247
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
248
248
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
249
249
|
return `export const useInfinite${operationName} = <
|
|
250
250
|
TData = ${operationResultType},
|
|
@@ -268,8 +268,8 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
268
268
|
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
|
|
269
269
|
this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
|
|
270
270
|
const hookConfig = this.visitor.queryMethodMap;
|
|
271
|
-
this.visitor.
|
|
272
|
-
this.visitor.
|
|
271
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
272
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
273
273
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
274
274
|
return `export const use${operationName} = <
|
|
275
275
|
TData = ${operationResultType},
|
|
@@ -288,10 +288,11 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
|
|
|
288
288
|
}
|
|
289
289
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
290
290
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
291
|
-
this.visitor.
|
|
291
|
+
const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
|
|
292
|
+
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
|
|
292
293
|
const hookConfig = this.visitor.queryMethodMap;
|
|
293
|
-
this.visitor.
|
|
294
|
-
this.visitor.
|
|
294
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
295
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
295
296
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
296
297
|
return `export const use${operationName} = <
|
|
297
298
|
TError = ${this.visitor.config.errorType},
|
|
@@ -361,8 +362,8 @@ ${this.getFetchParams()}
|
|
|
361
362
|
generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
362
363
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
363
364
|
const hookConfig = this.visitor.queryMethodMap;
|
|
364
|
-
this.visitor.
|
|
365
|
-
this.visitor.
|
|
365
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
|
|
366
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
|
|
366
367
|
const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
|
|
367
368
|
return `export const useInfinite${operationName} = <
|
|
368
369
|
TData = ${operationResultType},
|
|
@@ -381,8 +382,8 @@ ${this.getFetchParams()}
|
|
|
381
382
|
generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
382
383
|
const variables = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
383
384
|
const hookConfig = this.visitor.queryMethodMap;
|
|
384
|
-
this.visitor.
|
|
385
|
-
this.visitor.
|
|
385
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.query.hook);
|
|
386
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.query.options);
|
|
386
387
|
const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
|
|
387
388
|
return `export const use${operationName} = <
|
|
388
389
|
TData = ${operationResultType},
|
|
@@ -400,8 +401,8 @@ ${this.getFetchParams()}
|
|
|
400
401
|
generateMutationHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
|
|
401
402
|
const variables = `variables?: ${operationVariablesTypes}`;
|
|
402
403
|
const hookConfig = this.visitor.queryMethodMap;
|
|
403
|
-
this.visitor.
|
|
404
|
-
this.visitor.
|
|
404
|
+
this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.mutation.hook);
|
|
405
|
+
this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.mutation.options);
|
|
405
406
|
const options = `options?: ${hookConfig.mutation.options}<${operationResultType}, TError, ${operationVariablesTypes}, TContext>`;
|
|
406
407
|
return `export const use${operationName} = <
|
|
407
408
|
TError = ${this.visitor.config.errorType},
|
|
@@ -431,7 +432,8 @@ class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
431
432
|
addInfiniteQuery: getConfigValue(rawConfig.addInfiniteQuery, false),
|
|
432
433
|
});
|
|
433
434
|
this.rawConfig = rawConfig;
|
|
434
|
-
this.
|
|
435
|
+
this.reactQueryHookIdentifiersInUse = new Set();
|
|
436
|
+
this.reactQueryOptionsIdentifiersInUse = new Set();
|
|
435
437
|
this.queryMethodMap = {
|
|
436
438
|
infiniteQuery: {
|
|
437
439
|
hook: 'useInfiniteQuery',
|
|
@@ -475,9 +477,13 @@ class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
475
477
|
return baseImports;
|
|
476
478
|
}
|
|
477
479
|
if (this.config.addInfiniteQuery) {
|
|
478
|
-
this.
|
|
480
|
+
this.reactQueryOptionsIdentifiersInUse.add('QueryFunctionContext');
|
|
479
481
|
}
|
|
480
|
-
|
|
482
|
+
const hookAndTypeImports = [
|
|
483
|
+
...Array.from(this.reactQueryHookIdentifiersInUse),
|
|
484
|
+
...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
|
|
485
|
+
];
|
|
486
|
+
return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from 'react-query';`];
|
|
481
487
|
}
|
|
482
488
|
getFetcherImplementation() {
|
|
483
489
|
return this.fetcher.generateFetcherImplementaion();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.9",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating a ready-to-use React-Query Hooks based on GraphQL operations",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
package/visitor.d.ts
CHANGED
|
@@ -29,7 +29,8 @@ export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryR
|
|
|
29
29
|
protected rawConfig: ReactQueryRawPluginConfig;
|
|
30
30
|
private _externalImportPrefix;
|
|
31
31
|
fetcher: FetcherRenderer;
|
|
32
|
-
|
|
32
|
+
reactQueryHookIdentifiersInUse: Set<string>;
|
|
33
|
+
reactQueryOptionsIdentifiersInUse: Set<string>;
|
|
33
34
|
queryMethodMap: ReactQueryMethodMap;
|
|
34
35
|
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: ReactQueryRawPluginConfig, documents: Types.DocumentFile[]);
|
|
35
36
|
get imports(): Set<string>;
|