@graphql-codegen/typescript-react-query 3.3.2 → 3.5.1-alpha-05252ae4a.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.
Files changed (3) hide show
  1. package/index.js +7 -3
  2. package/index.mjs +7 -3
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -33,7 +33,7 @@ function generateQueryKeyMaker(node, operationName, operationVariablesTypes, has
33
33
  return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
34
34
  }
35
35
  function generateMutationKey(node) {
36
- return `'${node.name.value}'`;
36
+ return `['${node.name.value}']`;
37
37
  }
38
38
  function generateMutationKeyMaker(node, operationName) {
39
39
  return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
@@ -64,6 +64,8 @@ class CustomMapperFetcher {
64
64
  }
65
65
  generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
66
66
  const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
67
+ const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
68
+ this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
67
69
  const hookConfig = this.visitor.queryMethodMap;
68
70
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
69
71
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.infiniteQuery.options);
@@ -89,6 +91,8 @@ class CustomMapperFetcher {
89
91
  }
90
92
  generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
91
93
  const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
94
+ const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
95
+ this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
92
96
  const hookConfig = this.visitor.queryMethodMap;
93
97
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.query.hook);
94
98
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.query.options);
@@ -137,8 +141,8 @@ class CustomMapperFetcher {
137
141
  return '';
138
142
  const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
139
143
  const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
140
- const impl = `${typedFetcher}(${documentVariableName}, variables)`;
141
- return `\nuse${operationName}.fetcher = (${variables}) => ${impl};`;
144
+ const impl = `${typedFetcher}(${documentVariableName}, variables, options)`;
145
+ return `\nuse${operationName}.fetcher = (${variables}, options?: RequestInit['headers']) => ${impl};`;
142
146
  }
143
147
  }
144
148
 
package/index.mjs CHANGED
@@ -27,7 +27,7 @@ function generateQueryKeyMaker(node, operationName, operationVariablesTypes, has
27
27
  return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
28
28
  }
29
29
  function generateMutationKey(node) {
30
- return `'${node.name.value}'`;
30
+ return `['${node.name.value}']`;
31
31
  }
32
32
  function generateMutationKeyMaker(node, operationName) {
33
33
  return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
@@ -58,6 +58,8 @@ class CustomMapperFetcher {
58
58
  }
59
59
  generateInfiniteQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
60
60
  const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
61
+ const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
62
+ this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
61
63
  const hookConfig = this.visitor.queryMethodMap;
62
64
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.infiniteQuery.hook);
63
65
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.infiniteQuery.options);
@@ -83,6 +85,8 @@ class CustomMapperFetcher {
83
85
  }
84
86
  generateQueryHook(node, documentVariableName, operationName, operationResultType, operationVariablesTypes, hasRequiredVariables) {
85
87
  const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
88
+ const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
89
+ this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
86
90
  const hookConfig = this.visitor.queryMethodMap;
87
91
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.query.hook);
88
92
  this.visitor.reactQueryIdentifiersInUse.add(hookConfig.query.options);
@@ -131,8 +135,8 @@ class CustomMapperFetcher {
131
135
  return '';
132
136
  const variables = `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
133
137
  const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
134
- const impl = `${typedFetcher}(${documentVariableName}, variables)`;
135
- return `\nuse${operationName}.fetcher = (${variables}) => ${impl};`;
138
+ const impl = `${typedFetcher}(${documentVariableName}, variables, options)`;
139
+ return `\nuse${operationName}.fetcher = (${variables}, options?: RequestInit['headers']) => ${impl};`;
136
140
  }
137
141
  }
138
142
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-react-query",
3
- "version": "3.3.2",
3
+ "version": "3.5.1-alpha-05252ae4a.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
9
  "@graphql-codegen/plugin-helpers": "^2.3.2",
10
- "@graphql-codegen/visitor-plugin-common": "2.5.2",
10
+ "@graphql-codegen/visitor-plugin-common": "2.6.0-alpha-05252ae4a.0",
11
11
  "auto-bind": "~4.0.0",
12
12
  "change-case-all": "1.0.14",
13
13
  "tslib": "~2.3.0"