@graphql-codegen/typescript-react-query 3.2.1-alpha-ac95f9557.0 → 3.2.3-alpha-23d229715.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.
- package/config.d.ts +14 -12
- package/index.js +3 -2
- package/index.mjs +3 -2
- package/package.json +4 -3
package/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
2
|
export declare type HardcodedFetch = {
|
|
3
3
|
endpoint: string;
|
|
4
|
-
fetchParams?: string
|
|
4
|
+
fetchParams?: string | Record<string, any>;
|
|
5
5
|
};
|
|
6
6
|
export declare type CustomFetch = {
|
|
7
7
|
func: string;
|
|
@@ -14,9 +14,10 @@ export declare type CustomFetch = {
|
|
|
14
14
|
*/
|
|
15
15
|
export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports'> {
|
|
16
16
|
/**
|
|
17
|
-
* @description Customize the fetcher you wish to use in the generated file. React-Query is agnostic to the data-
|
|
17
|
+
* @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
18
|
*
|
|
19
19
|
* The following options are available to use:
|
|
20
|
+
*
|
|
20
21
|
* - 'fetch' - requires you to specify endpoint and headers on each call, and uses `fetch` to do the actual http call.
|
|
21
22
|
* - `{ endpoint: string, fetchParams: RequestInit }`: hardcode your endpoint and fetch options into the generated output, using the environment `fetch` method. You can also use `process.env.MY_VAR` as endpoint or header value.
|
|
22
23
|
* - `file#identifier` - You can use custom fetcher method that should implement the exported `ReactQueryFetcher` interface. Example: `./my-fetcher#myCustomFetcher`.
|
|
@@ -28,11 +29,12 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
28
29
|
* @description For each generate query hook adds `document` field with a
|
|
29
30
|
* corresponding GraphQL query. Useful for `queryClient.fetchQuery`.
|
|
30
31
|
* @exampleMarkdown
|
|
32
|
+
* <!-- prettier-ignore -->
|
|
31
33
|
* ```ts
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* queryClient.fetchQuery(
|
|
35
|
+
* useUserDetailsQuery.getKey(variables),
|
|
36
|
+
* () => gqlRequest(useUserDetailsQuery.document, variables)
|
|
37
|
+
* )
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
40
|
exposeDocument?: boolean;
|
|
@@ -41,9 +43,9 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
41
43
|
* @description For each generate query hook adds getKey(variables: QueryVariables) function. Useful for cache updates.
|
|
42
44
|
* @exampleMarkdown
|
|
43
45
|
* ```ts
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
46
|
+
* const query = useUserDetailsQuery(...)
|
|
47
|
+
* const key = useUserDetailsQuery.getKey({ id: theUsersId })
|
|
48
|
+
* // use key in a cache update after a mutation
|
|
47
49
|
* ```
|
|
48
50
|
*/
|
|
49
51
|
exposeQueryKeys?: boolean;
|
|
@@ -52,8 +54,8 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
52
54
|
* @description For each generate mutation hook adds getKey() function. Useful for call outside of functional component.
|
|
53
55
|
* @exampleMarkdown
|
|
54
56
|
* ```ts
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
+
* const mutation = useUserDetailsMutation(...)
|
|
58
|
+
* const key = useUserDetailsMutation.getKey()
|
|
57
59
|
* ```
|
|
58
60
|
*/
|
|
59
61
|
exposeMutationKeys?: boolean;
|
|
@@ -63,7 +65,7 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
63
65
|
* It is useful for `queryClient.fetchQuery` and `queryClient.prefetchQuery`.
|
|
64
66
|
* @exampleMarkdown
|
|
65
67
|
* ```ts
|
|
66
|
-
*
|
|
68
|
+
* await queryClient.prefetchQuery(userQuery.getKey(), () => userQuery.fetcher())
|
|
67
69
|
* ```
|
|
68
70
|
*/
|
|
69
71
|
exposeFetcher?: boolean;
|
package/index.js
CHANGED
|
@@ -32,7 +32,7 @@ function generateMutationKey(node) {
|
|
|
32
32
|
return `'${node.name.value}'`;
|
|
33
33
|
}
|
|
34
34
|
function generateMutationKeyMaker(node, operationName) {
|
|
35
|
-
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)}
|
|
35
|
+
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
class CustomMapperFetcher {
|
|
@@ -331,7 +331,8 @@ class HardcodedFetchFetcher {
|
|
|
331
331
|
getFetchParams() {
|
|
332
332
|
let fetchParamsPartial = '';
|
|
333
333
|
if (this.config.fetchParams) {
|
|
334
|
-
|
|
334
|
+
const fetchParamsString = typeof this.config.fetchParams === 'string' ? this.config.fetchParams : JSON.stringify(this.config.fetchParams);
|
|
335
|
+
fetchParamsPartial = `\n ...(${fetchParamsString}),`;
|
|
335
336
|
}
|
|
336
337
|
return ` method: "POST",${fetchParamsPartial}`;
|
|
337
338
|
}
|
package/index.mjs
CHANGED
|
@@ -26,7 +26,7 @@ function generateMutationKey(node) {
|
|
|
26
26
|
return `'${node.name.value}'`;
|
|
27
27
|
}
|
|
28
28
|
function generateMutationKeyMaker(node, operationName) {
|
|
29
|
-
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)}
|
|
29
|
+
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
class CustomMapperFetcher {
|
|
@@ -325,7 +325,8 @@ class HardcodedFetchFetcher {
|
|
|
325
325
|
getFetchParams() {
|
|
326
326
|
let fetchParamsPartial = '';
|
|
327
327
|
if (this.config.fetchParams) {
|
|
328
|
-
|
|
328
|
+
const fetchParamsString = typeof this.config.fetchParams === 'string' ? this.config.fetchParams : JSON.stringify(this.config.fetchParams);
|
|
329
|
+
fetchParamsPartial = `\n ...(${fetchParamsString}),`;
|
|
329
330
|
}
|
|
330
331
|
return ` method: "POST",${fetchParamsPartial}`;
|
|
331
332
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3-alpha-23d229715.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
|
"graphql-tag": "^2.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-codegen/plugin-helpers": "
|
|
11
|
-
"@graphql-codegen/visitor-plugin-common": "2.5.
|
|
10
|
+
"@graphql-codegen/plugin-helpers": "2.4.0-alpha-23d229715.0",
|
|
11
|
+
"@graphql-codegen/visitor-plugin-common": "2.5.2-alpha-23d229715.0",
|
|
12
12
|
"auto-bind": "~4.0.0",
|
|
13
13
|
"change-case-all": "1.0.14",
|
|
14
14
|
"tslib": "~2.3.0"
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"definition": "index.d.ts"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
|
+
"./package.json": "./package.json",
|
|
29
30
|
".": {
|
|
30
31
|
"require": "./index.js",
|
|
31
32
|
"import": "./index.mjs"
|