@graphql-codegen/typescript-react-query 3.6.2 → 4.0.1-alpha-ab1d4bbb7.0

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.
@@ -55,7 +55,7 @@ ${this.getFetchParams()}
55
55
  TData = ${operationResultType},
56
56
  TError = ${this.visitor.config.errorType}
57
57
  >(
58
- pageParamKey: keyof ${operationVariablesTypes},
58
+ _pageParamKey: keyof ${operationVariablesTypes},
59
59
  ${variables},
60
60
  ${options}
61
61
  ) =>
@@ -33,13 +33,13 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
33
33
  const hookConfig = this.visitor.queryMethodMap;
34
34
  this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
35
35
  this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
36
- const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
36
+ const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
37
37
  return `export const useInfinite${operationName} = <
38
38
  TData = ${operationResultType},
39
39
  TError = ${this.visitor.config.errorType}
40
40
  >(
41
41
  dataSource: { endpoint: string, fetchParams?: RequestInit },
42
- pageParamKey: keyof ${operationVariablesTypes},
42
+ _pageParamKey: keyof ${operationVariablesTypes},
43
43
  ${variables},
44
44
  ${options}
45
45
  ) =>
@@ -24,7 +24,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
24
24
  TData = ${operationResultType},
25
25
  TError = ${this.visitor.config.errorType}
26
26
  >(
27
- pageParamKey: keyof ${operationVariablesTypes},
27
+ _pageParamKey: keyof ${operationVariablesTypes},
28
28
  client: GraphQLClient,
29
29
  ${variables},
30
30
  ${options},
package/cjs/visitor.js CHANGED
@@ -20,6 +20,7 @@ class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
20
20
  exposeMutationKeys: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeMutationKeys, false),
21
21
  exposeFetcher: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exposeFetcher, false),
22
22
  addInfiniteQuery: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.addInfiniteQuery, false),
23
+ legacyMode: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.legacyMode, false),
23
24
  });
24
25
  this.rawConfig = rawConfig;
25
26
  this.reactQueryHookIdentifiersInUse = new Set();
@@ -66,14 +67,12 @@ class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
66
67
  if (!this.hasOperations) {
67
68
  return baseImports;
68
69
  }
69
- if (this.config.addInfiniteQuery) {
70
- this.reactQueryOptionsIdentifiersInUse.add('QueryFunctionContext');
71
- }
72
70
  const hookAndTypeImports = [
73
71
  ...Array.from(this.reactQueryHookIdentifiersInUse),
74
72
  ...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
75
73
  ];
76
- return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from 'react-query';`];
74
+ const moduleName = this.config.legacyMode ? 'react-query' : '@tanstack/react-query';
75
+ return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`];
77
76
  }
78
77
  getFetcherImplementation() {
79
78
  return this.fetcher.generateFetcherImplementaion();
@@ -52,7 +52,7 @@ ${this.getFetchParams()}
52
52
  TData = ${operationResultType},
53
53
  TError = ${this.visitor.config.errorType}
54
54
  >(
55
- pageParamKey: keyof ${operationVariablesTypes},
55
+ _pageParamKey: keyof ${operationVariablesTypes},
56
56
  ${variables},
57
57
  ${options}
58
58
  ) =>
@@ -30,13 +30,13 @@ function fetcher<TData, TVariables>(endpoint: string, requestInit: RequestInit,
30
30
  const hookConfig = this.visitor.queryMethodMap;
31
31
  this.visitor.reactQueryHookIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
32
32
  this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
33
- const options = `options?: ${hookConfig.query.options}<${operationResultType}, TError, TData>`;
33
+ const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
34
34
  return `export const useInfinite${operationName} = <
35
35
  TData = ${operationResultType},
36
36
  TError = ${this.visitor.config.errorType}
37
37
  >(
38
38
  dataSource: { endpoint: string, fetchParams?: RequestInit },
39
- pageParamKey: keyof ${operationVariablesTypes},
39
+ _pageParamKey: keyof ${operationVariablesTypes},
40
40
  ${variables},
41
41
  ${options}
42
42
  ) =>
@@ -21,7 +21,7 @@ function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variab
21
21
  TData = ${operationResultType},
22
22
  TError = ${this.visitor.config.errorType}
23
23
  >(
24
- pageParamKey: keyof ${operationVariablesTypes},
24
+ _pageParamKey: keyof ${operationVariablesTypes},
25
25
  client: GraphQLClient,
26
26
  ${variables},
27
27
  ${options},
package/esm/visitor.js CHANGED
@@ -16,6 +16,7 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
16
16
  exposeMutationKeys: getConfigValue(rawConfig.exposeMutationKeys, false),
17
17
  exposeFetcher: getConfigValue(rawConfig.exposeFetcher, false),
18
18
  addInfiniteQuery: getConfigValue(rawConfig.addInfiniteQuery, false),
19
+ legacyMode: getConfigValue(rawConfig.legacyMode, false),
19
20
  });
20
21
  this.rawConfig = rawConfig;
21
22
  this.reactQueryHookIdentifiersInUse = new Set();
@@ -62,14 +63,12 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
62
63
  if (!this.hasOperations) {
63
64
  return baseImports;
64
65
  }
65
- if (this.config.addInfiniteQuery) {
66
- this.reactQueryOptionsIdentifiersInUse.add('QueryFunctionContext');
67
- }
68
66
  const hookAndTypeImports = [
69
67
  ...Array.from(this.reactQueryHookIdentifiersInUse),
70
68
  ...Array.from(this.reactQueryOptionsIdentifiersInUse).map(identifier => `${this.config.useTypeImports ? 'type ' : ''}${identifier}`),
71
69
  ];
72
- return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from 'react-query';`];
70
+ const moduleName = this.config.legacyMode ? 'react-query' : '@tanstack/react-query';
71
+ return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`];
73
72
  }
74
73
  getFetcherImplementation() {
75
74
  return this.fetcher.generateFetcherImplementaion();
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-react-query",
3
- "version": "3.6.2",
3
+ "version": "4.0.1-alpha-ab1d4bbb7.0",
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"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/plugin-helpers": "^2.6.0",
10
- "@graphql-codegen/visitor-plugin-common": "2.12.0",
9
+ "@graphql-codegen/plugin-helpers": "^2.6.1-alpha-ab1d4bbb7.0",
10
+ "@graphql-codegen/visitor-plugin-common": "2.12.1-alpha-ab1d4bbb7.0",
11
11
  "auto-bind": "~4.0.0",
12
12
  "change-case-all": "1.0.14",
13
13
  "tslib": "~2.4.0"
@@ -11,8 +11,11 @@ export declare type CustomFetch = {
11
11
  * @description This plugin generates `React-Query` Hooks with TypeScript typings.
12
12
  *
13
13
  * It extends the basic TypeScript plugins: `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations` - and thus shares a similar configuration.
14
+ *
15
+ * > **If you are using the `react-query` package instead of the `@tanstack/react-query` package in your project, please set the `legacyMode` option to `true`.**
16
+ *
14
17
  */
15
- export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports'> {
18
+ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports' | 'legacyMode'> {
16
19
  /**
17
20
  * @description Customize the fetcher you wish to use in the generated file. React-Query is agnostic to the data-fetching layer, so you should provide it, or use a custom one.
18
21
  *
@@ -78,4 +81,9 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
78
81
  * @description Adds an Infinite Query along side the standard one
79
82
  */
80
83
  addInfiniteQuery?: boolean;
84
+ /**
85
+ * @default true
86
+ * @description If false, it will work with `@tanstack/react-query`, default value is true.
87
+ */
88
+ legacyMode?: boolean;
81
89
  }
@@ -10,6 +10,7 @@ export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig {
10
10
  exposeMutationKeys: boolean;
11
11
  exposeFetcher: boolean;
12
12
  addInfiniteQuery: boolean;
13
+ legacyMode: boolean;
13
14
  }
14
15
  export interface ReactQueryMethodMap {
15
16
  infiniteQuery: {