@graphql-codegen/typescript-react-query 5.1.0-alpha-20231024141714-d4d2e5e06 → 6.0.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/cjs/fetcher-custom-mapper.js +31 -59
- package/cjs/fetcher-fetch-hardcoded.js +28 -56
- package/cjs/fetcher-fetch.js +34 -53
- package/cjs/fetcher-graphql-request.js +49 -83
- package/cjs/fetcher.js +220 -0
- package/cjs/index.js +5 -0
- package/cjs/visitor.js +47 -42
- package/esm/fetcher-custom-mapper.js +30 -59
- package/esm/fetcher-fetch-hardcoded.js +27 -56
- package/esm/fetcher-fetch.js +33 -53
- package/esm/fetcher-graphql-request.js +48 -83
- package/esm/fetcher.js +215 -0
- package/esm/index.js +5 -0
- package/esm/visitor.js +47 -42
- package/package.json +1 -1
- package/typings/config.d.cts +36 -23
- package/typings/config.d.ts +36 -23
- package/typings/fetcher-custom-mapper.d.cts +8 -9
- package/typings/fetcher-custom-mapper.d.ts +8 -9
- package/typings/fetcher-fetch-hardcoded.d.cts +8 -9
- package/typings/fetcher-fetch-hardcoded.d.ts +8 -9
- package/typings/fetcher-fetch.d.cts +8 -9
- package/typings/fetcher-fetch.d.ts +8 -9
- package/typings/fetcher-graphql-request.d.cts +8 -9
- package/typings/fetcher-graphql-request.d.ts +8 -9
- package/typings/fetcher.d.cts +73 -6
- package/typings/fetcher.d.ts +73 -6
- package/typings/visitor.d.cts +2 -27
- package/typings/visitor.d.ts +2 -27
- package/cjs/variables-generator.js +0 -45
- package/esm/variables-generator.js +0 -33
- package/typings/variables-generator.d.cts +0 -10
- package/typings/variables-generator.d.ts +0 -10
package/esm/visitor.js
CHANGED
|
@@ -5,9 +5,9 @@ import { CustomMapperFetcher } from './fetcher-custom-mapper.js';
|
|
|
5
5
|
import { HardcodedFetchFetcher } from './fetcher-fetch-hardcoded.js';
|
|
6
6
|
import { FetchFetcher } from './fetcher-fetch.js';
|
|
7
7
|
import { GraphQLRequestClientFetcher } from './fetcher-graphql-request.js';
|
|
8
|
-
import { generateInfiniteQueryKeyMaker, generateInfiniteQueryRootKeyMaker, generateMutationKeyMaker, generateQueryKeyMaker, generateQueryRootKeyMaker, } from './variables-generator.js';
|
|
9
8
|
export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
10
9
|
constructor(schema, fragments, rawConfig, documents) {
|
|
10
|
+
const defaultReactQueryVersion = !rawConfig.reactQueryVersion && rawConfig.legacyMode ? 3 : 4;
|
|
11
11
|
super(schema, fragments, rawConfig, {
|
|
12
12
|
documentMode: DocumentMode.string,
|
|
13
13
|
errorType: getConfigValue(rawConfig.errorType, 'unknown'),
|
|
@@ -17,26 +17,13 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
17
17
|
exposeMutationKeys: getConfigValue(rawConfig.exposeMutationKeys, false),
|
|
18
18
|
exposeFetcher: getConfigValue(rawConfig.exposeFetcher, false),
|
|
19
19
|
addInfiniteQuery: getConfigValue(rawConfig.addInfiniteQuery, false),
|
|
20
|
-
|
|
20
|
+
addSuspenseQuery: getConfigValue(rawConfig.addSuspenseQuery, false),
|
|
21
|
+
reactQueryVersion: getConfigValue(rawConfig.reactQueryVersion, defaultReactQueryVersion),
|
|
21
22
|
reactQueryImportFrom: getConfigValue(rawConfig.reactQueryImportFrom, ''),
|
|
22
23
|
});
|
|
23
24
|
this.rawConfig = rawConfig;
|
|
24
25
|
this.reactQueryHookIdentifiersInUse = new Set();
|
|
25
26
|
this.reactQueryOptionsIdentifiersInUse = new Set();
|
|
26
|
-
this.queryMethodMap = {
|
|
27
|
-
infiniteQuery: {
|
|
28
|
-
hook: 'useInfiniteQuery',
|
|
29
|
-
options: 'UseInfiniteQueryOptions',
|
|
30
|
-
},
|
|
31
|
-
query: {
|
|
32
|
-
hook: 'useQuery',
|
|
33
|
-
options: 'UseQueryOptions',
|
|
34
|
-
},
|
|
35
|
-
mutation: {
|
|
36
|
-
hook: 'useMutation',
|
|
37
|
-
options: 'UseMutationOptions',
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
27
|
this._externalImportPrefix = this.config.importOperationTypesFrom
|
|
41
28
|
? `${this.config.importOperationTypesFrom}.`
|
|
42
29
|
: '';
|
|
@@ -73,13 +60,13 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
73
60
|
];
|
|
74
61
|
const moduleName = this.config.reactQueryImportFrom
|
|
75
62
|
? this.config.reactQueryImportFrom
|
|
76
|
-
: this.config.
|
|
63
|
+
: this.config.reactQueryVersion <= 3
|
|
77
64
|
? 'react-query'
|
|
78
65
|
: '@tanstack/react-query';
|
|
79
66
|
return [...baseImports, `import { ${hookAndTypeImports.join(', ')} } from '${moduleName}';`];
|
|
80
67
|
}
|
|
81
68
|
getFetcherImplementation() {
|
|
82
|
-
return this.fetcher.
|
|
69
|
+
return this.fetcher.generateFetcherImplementation();
|
|
83
70
|
}
|
|
84
71
|
_getHookSuffix(name, operationType) {
|
|
85
72
|
if (this.config.omitOperationSuffix) {
|
|
@@ -102,45 +89,63 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
|
|
|
102
89
|
useTypesPrefix: false,
|
|
103
90
|
useTypesSuffix: false,
|
|
104
91
|
});
|
|
92
|
+
const generateConfig = {
|
|
93
|
+
node,
|
|
94
|
+
documentVariableName,
|
|
95
|
+
operationResultType,
|
|
96
|
+
operationVariablesTypes,
|
|
97
|
+
hasRequiredVariables,
|
|
98
|
+
operationName,
|
|
99
|
+
};
|
|
105
100
|
operationResultType = this._externalImportPrefix + operationResultType;
|
|
106
101
|
operationVariablesTypes = this._externalImportPrefix + operationVariablesTypes;
|
|
102
|
+
const queries = [];
|
|
103
|
+
const getOutputFromQueries = () => `\n${queries.join('\n\n')}\n`;
|
|
107
104
|
if (operationType === 'Query') {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
105
|
+
const addQuery = (generateConfig, isSuspense = false) => {
|
|
106
|
+
const { hook, getKey, rootKey, document } = this.fetcher.generateQueryOutput(generateConfig, isSuspense);
|
|
107
|
+
queries.push(hook);
|
|
108
|
+
if (this.config.exposeDocument)
|
|
109
|
+
queries.push(document);
|
|
110
|
+
if (this.config.exposeQueryKeys)
|
|
111
|
+
queries.push(getKey);
|
|
112
|
+
if (this.config.exposeQueryRootKeys)
|
|
113
|
+
queries.push(rootKey);
|
|
114
|
+
};
|
|
115
|
+
addQuery(generateConfig);
|
|
116
|
+
if (this.config.addSuspenseQuery)
|
|
117
|
+
addQuery(generateConfig, true);
|
|
118
118
|
if (this.config.addInfiniteQuery) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
const addInfiniteQuery = (generateConfig, isSuspense = false) => {
|
|
120
|
+
const { hook, getKey, rootKey } = this.fetcher.generateInfiniteQueryOutput(generateConfig, isSuspense);
|
|
121
|
+
queries.push(hook);
|
|
122
|
+
if (this.config.exposeQueryKeys)
|
|
123
|
+
queries.push(getKey);
|
|
124
|
+
if (this.config.exposeQueryRootKeys)
|
|
125
|
+
queries.push(rootKey);
|
|
126
|
+
};
|
|
127
|
+
addInfiniteQuery(generateConfig);
|
|
128
|
+
if (this.config.addSuspenseQuery) {
|
|
129
|
+
addInfiniteQuery(generateConfig, true);
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
// The reason we're looking at the private field of the CustomMapperFetcher to see if it's a react hook
|
|
128
133
|
// is to prevent calling generateFetcherFetch for each query since all the queries won't be able to generate
|
|
129
134
|
// a fetcher field anyways.
|
|
130
135
|
if (this.config.exposeFetcher && !this.fetcher._isReactHook) {
|
|
131
|
-
|
|
136
|
+
queries.push(this.fetcher.generateFetcherFetch(generateConfig));
|
|
132
137
|
}
|
|
133
|
-
return
|
|
138
|
+
return getOutputFromQueries();
|
|
134
139
|
}
|
|
135
140
|
if (operationType === 'Mutation') {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
const { hook, getKey } = this.fetcher.generateMutationOutput(generateConfig);
|
|
142
|
+
queries.push(hook);
|
|
143
|
+
if (this.config.exposeMutationKeys)
|
|
144
|
+
queries.push(getKey);
|
|
140
145
|
if (this.config.exposeFetcher && !this.fetcher._isReactHook) {
|
|
141
|
-
|
|
146
|
+
queries.push(this.fetcher.generateFetcherFetch(generateConfig));
|
|
142
147
|
}
|
|
143
|
-
return
|
|
148
|
+
return getOutputFromQueries();
|
|
144
149
|
}
|
|
145
150
|
if (operationType === 'Subscription') {
|
|
146
151
|
// eslint-disable-next-line no-console
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.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"
|
package/typings/config.d.cts
CHANGED
|
@@ -10,26 +10,12 @@ export type CustomFetch = {
|
|
|
10
10
|
export type GraphQlRequest = 'graphql-request' | {
|
|
11
11
|
clientImportPath: string;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
* @description This plugin generates `React-Query` Hooks with TypeScript typings.
|
|
15
|
-
*
|
|
16
|
-
* It extends the basic TypeScript plugins: `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations` - and thus shares a similar configuration.
|
|
17
|
-
*
|
|
18
|
-
* > **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`.**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports' | 'legacyMode'> {
|
|
13
|
+
export interface BaseReactQueryPluginConfig {
|
|
22
14
|
/**
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
* The following options are available to use:
|
|
26
|
-
*
|
|
27
|
-
* - 'fetch' - requires you to specify endpoint and headers on each call, and uses `fetch` to do the actual http call.
|
|
28
|
-
* - `{ 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.
|
|
29
|
-
* - `file#identifier` - You can use custom fetcher method that should implement the exported `ReactQueryFetcher` interface. Example: `./my-fetcher#myCustomFetcher`.
|
|
30
|
-
* - `graphql-request`: Will generate each hook with `client` argument, where you should pass your own `GraphQLClient` (created from `graphql-request`).
|
|
15
|
+
* @default unknown
|
|
16
|
+
* @description Changes the default "TError" generic type.
|
|
31
17
|
*/
|
|
32
|
-
|
|
18
|
+
errorType?: string;
|
|
33
19
|
/**
|
|
34
20
|
* @default false
|
|
35
21
|
* @description For each generate query hook adds `document` field with a
|
|
@@ -85,21 +71,27 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
85
71
|
* ```
|
|
86
72
|
*/
|
|
87
73
|
exposeFetcher?: boolean;
|
|
88
|
-
/**
|
|
89
|
-
* @default unknown
|
|
90
|
-
* @description Changes the default "TError" generic type.
|
|
91
|
-
*/
|
|
92
|
-
errorType?: string;
|
|
93
74
|
/**
|
|
94
75
|
* @default false
|
|
95
76
|
* @description Adds an Infinite Query along side the standard one
|
|
96
77
|
*/
|
|
97
78
|
addInfiniteQuery?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* @default false
|
|
81
|
+
* @description Adds a Suspense Query along side the standard one
|
|
82
|
+
*/
|
|
83
|
+
addSuspenseQuery?: boolean;
|
|
98
84
|
/**
|
|
99
85
|
* @default false
|
|
100
86
|
* @description If true, it imports `react-query` not `@tanstack/react-query`, default is false.
|
|
87
|
+
* @deprecated Please use `reactQueryVersion` instead.
|
|
101
88
|
*/
|
|
102
89
|
legacyMode?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @default 4
|
|
92
|
+
* @description The version of react-query to use. Will override the legacyMode option.
|
|
93
|
+
*/
|
|
94
|
+
reactQueryVersion?: 3 | 4 | 5;
|
|
103
95
|
/**
|
|
104
96
|
* @default empty
|
|
105
97
|
* @description Add custom import for react-query.
|
|
@@ -111,3 +103,24 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
111
103
|
*/
|
|
112
104
|
reactQueryImportFrom?: string;
|
|
113
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* @description This plugin generates `React-Query` Hooks with TypeScript typings.
|
|
108
|
+
*
|
|
109
|
+
* It extends the basic TypeScript plugins: `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations` - and thus shares a similar configuration.
|
|
110
|
+
*
|
|
111
|
+
* > **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`.**
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports' | 'legacyMode'>, BaseReactQueryPluginConfig {
|
|
115
|
+
/**
|
|
116
|
+
* @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.
|
|
117
|
+
*
|
|
118
|
+
* The following options are available to use:
|
|
119
|
+
*
|
|
120
|
+
* - 'fetch' - requires you to specify endpoint and headers on each call, and uses `fetch` to do the actual http call.
|
|
121
|
+
* - `{ 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.
|
|
122
|
+
* - `file#identifier` - You can use custom fetcher method that should implement the exported `ReactQueryFetcher` interface. Example: `./my-fetcher#myCustomFetcher`.
|
|
123
|
+
* - `graphql-request`: Will generate each hook with `client` argument, where you should pass your own `GraphQLClient` (created from `graphql-request`).
|
|
124
|
+
*/
|
|
125
|
+
fetcher?: 'fetch' | HardcodedFetch | GraphQlRequest | CustomFetch;
|
|
126
|
+
}
|
package/typings/config.d.ts
CHANGED
|
@@ -10,26 +10,12 @@ export type CustomFetch = {
|
|
|
10
10
|
export type GraphQlRequest = 'graphql-request' | {
|
|
11
11
|
clientImportPath: string;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
* @description This plugin generates `React-Query` Hooks with TypeScript typings.
|
|
15
|
-
*
|
|
16
|
-
* It extends the basic TypeScript plugins: `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations` - and thus shares a similar configuration.
|
|
17
|
-
*
|
|
18
|
-
* > **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`.**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports' | 'legacyMode'> {
|
|
13
|
+
export interface BaseReactQueryPluginConfig {
|
|
22
14
|
/**
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
* The following options are available to use:
|
|
26
|
-
*
|
|
27
|
-
* - 'fetch' - requires you to specify endpoint and headers on each call, and uses `fetch` to do the actual http call.
|
|
28
|
-
* - `{ 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.
|
|
29
|
-
* - `file#identifier` - You can use custom fetcher method that should implement the exported `ReactQueryFetcher` interface. Example: `./my-fetcher#myCustomFetcher`.
|
|
30
|
-
* - `graphql-request`: Will generate each hook with `client` argument, where you should pass your own `GraphQLClient` (created from `graphql-request`).
|
|
15
|
+
* @default unknown
|
|
16
|
+
* @description Changes the default "TError" generic type.
|
|
31
17
|
*/
|
|
32
|
-
|
|
18
|
+
errorType?: string;
|
|
33
19
|
/**
|
|
34
20
|
* @default false
|
|
35
21
|
* @description For each generate query hook adds `document` field with a
|
|
@@ -85,21 +71,27 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
85
71
|
* ```
|
|
86
72
|
*/
|
|
87
73
|
exposeFetcher?: boolean;
|
|
88
|
-
/**
|
|
89
|
-
* @default unknown
|
|
90
|
-
* @description Changes the default "TError" generic type.
|
|
91
|
-
*/
|
|
92
|
-
errorType?: string;
|
|
93
74
|
/**
|
|
94
75
|
* @default false
|
|
95
76
|
* @description Adds an Infinite Query along side the standard one
|
|
96
77
|
*/
|
|
97
78
|
addInfiniteQuery?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* @default false
|
|
81
|
+
* @description Adds a Suspense Query along side the standard one
|
|
82
|
+
*/
|
|
83
|
+
addSuspenseQuery?: boolean;
|
|
98
84
|
/**
|
|
99
85
|
* @default false
|
|
100
86
|
* @description If true, it imports `react-query` not `@tanstack/react-query`, default is false.
|
|
87
|
+
* @deprecated Please use `reactQueryVersion` instead.
|
|
101
88
|
*/
|
|
102
89
|
legacyMode?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @default 4
|
|
92
|
+
* @description The version of react-query to use. Will override the legacyMode option.
|
|
93
|
+
*/
|
|
94
|
+
reactQueryVersion?: 3 | 4 | 5;
|
|
103
95
|
/**
|
|
104
96
|
* @default empty
|
|
105
97
|
* @description Add custom import for react-query.
|
|
@@ -111,3 +103,24 @@ export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginC
|
|
|
111
103
|
*/
|
|
112
104
|
reactQueryImportFrom?: string;
|
|
113
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* @description This plugin generates `React-Query` Hooks with TypeScript typings.
|
|
108
|
+
*
|
|
109
|
+
* It extends the basic TypeScript plugins: `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations` - and thus shares a similar configuration.
|
|
110
|
+
*
|
|
111
|
+
* > **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`.**
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports' | 'legacyMode'>, BaseReactQueryPluginConfig {
|
|
115
|
+
/**
|
|
116
|
+
* @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.
|
|
117
|
+
*
|
|
118
|
+
* The following options are available to use:
|
|
119
|
+
*
|
|
120
|
+
* - 'fetch' - requires you to specify endpoint and headers on each call, and uses `fetch` to do the actual http call.
|
|
121
|
+
* - `{ 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.
|
|
122
|
+
* - `file#identifier` - You can use custom fetcher method that should implement the exported `ReactQueryFetcher` interface. Example: `./my-fetcher#myCustomFetcher`.
|
|
123
|
+
* - `graphql-request`: Will generate each hook with `client` argument, where you should pass your own `GraphQLClient` (created from `graphql-request`).
|
|
124
|
+
*/
|
|
125
|
+
fetcher?: 'fetch' | HardcodedFetch | GraphQlRequest | CustomFetch;
|
|
126
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
1
|
import { CustomFetch } from './config.cjs';
|
|
3
|
-
import { FetcherRenderer } from './fetcher.cjs';
|
|
2
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.cjs';
|
|
4
3
|
import { ReactQueryVisitor } from './visitor.cjs';
|
|
5
|
-
export declare class CustomMapperFetcher
|
|
6
|
-
|
|
4
|
+
export declare class CustomMapperFetcher extends FetcherRenderer {
|
|
5
|
+
protected visitor: ReactQueryVisitor;
|
|
7
6
|
private _mapper;
|
|
8
7
|
private _isReactHook;
|
|
9
8
|
constructor(visitor: ReactQueryVisitor, customFetcher: CustomFetch);
|
|
10
9
|
private getFetcherFnName;
|
|
11
|
-
|
|
12
|
-
generateInfiniteQueryHook(
|
|
13
|
-
generateQueryHook(
|
|
14
|
-
generateMutationHook(
|
|
15
|
-
generateFetcherFetch(
|
|
10
|
+
generateFetcherImplementation(): string;
|
|
11
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
12
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
13
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
14
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
16
15
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
1
|
import { CustomFetch } from './config.js';
|
|
3
|
-
import { FetcherRenderer } from './fetcher.js';
|
|
2
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.js';
|
|
4
3
|
import { ReactQueryVisitor } from './visitor.js';
|
|
5
|
-
export declare class CustomMapperFetcher
|
|
6
|
-
|
|
4
|
+
export declare class CustomMapperFetcher extends FetcherRenderer {
|
|
5
|
+
protected visitor: ReactQueryVisitor;
|
|
7
6
|
private _mapper;
|
|
8
7
|
private _isReactHook;
|
|
9
8
|
constructor(visitor: ReactQueryVisitor, customFetcher: CustomFetch);
|
|
10
9
|
private getFetcherFnName;
|
|
11
|
-
|
|
12
|
-
generateInfiniteQueryHook(
|
|
13
|
-
generateQueryHook(
|
|
14
|
-
generateMutationHook(
|
|
15
|
-
generateFetcherFetch(
|
|
10
|
+
generateFetcherImplementation(): string;
|
|
11
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
12
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
13
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
14
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
16
15
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
1
|
import { HardcodedFetch } from './config.cjs';
|
|
3
|
-
import { FetcherRenderer } from './fetcher.cjs';
|
|
2
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.cjs';
|
|
4
3
|
import { ReactQueryVisitor } from './visitor.cjs';
|
|
5
|
-
export declare class HardcodedFetchFetcher
|
|
6
|
-
|
|
4
|
+
export declare class HardcodedFetchFetcher extends FetcherRenderer {
|
|
5
|
+
protected visitor: ReactQueryVisitor;
|
|
7
6
|
private config;
|
|
8
7
|
constructor(visitor: ReactQueryVisitor, config: HardcodedFetch);
|
|
9
8
|
private getEndpoint;
|
|
10
9
|
private getFetchParams;
|
|
11
|
-
|
|
12
|
-
generateInfiniteQueryHook(
|
|
13
|
-
generateQueryHook(
|
|
14
|
-
generateMutationHook(
|
|
15
|
-
generateFetcherFetch(
|
|
10
|
+
generateFetcherImplementation(): string;
|
|
11
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
12
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
13
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
14
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
16
15
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
1
|
import { HardcodedFetch } from './config.js';
|
|
3
|
-
import { FetcherRenderer } from './fetcher.js';
|
|
2
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.js';
|
|
4
3
|
import { ReactQueryVisitor } from './visitor.js';
|
|
5
|
-
export declare class HardcodedFetchFetcher
|
|
6
|
-
|
|
4
|
+
export declare class HardcodedFetchFetcher extends FetcherRenderer {
|
|
5
|
+
protected visitor: ReactQueryVisitor;
|
|
7
6
|
private config;
|
|
8
7
|
constructor(visitor: ReactQueryVisitor, config: HardcodedFetch);
|
|
9
8
|
private getEndpoint;
|
|
10
9
|
private getFetchParams;
|
|
11
|
-
|
|
12
|
-
generateInfiniteQueryHook(
|
|
13
|
-
generateQueryHook(
|
|
14
|
-
generateMutationHook(
|
|
15
|
-
generateFetcherFetch(
|
|
10
|
+
generateFetcherImplementation(): string;
|
|
11
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
12
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
13
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
14
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
16
15
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FetcherRenderer } from './fetcher.cjs';
|
|
1
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.cjs';
|
|
3
2
|
import { ReactQueryVisitor } from './visitor.cjs';
|
|
4
|
-
export declare class FetchFetcher
|
|
5
|
-
|
|
3
|
+
export declare class FetchFetcher extends FetcherRenderer {
|
|
4
|
+
protected visitor: ReactQueryVisitor;
|
|
6
5
|
constructor(visitor: ReactQueryVisitor);
|
|
7
|
-
|
|
8
|
-
generateInfiniteQueryHook(
|
|
9
|
-
generateQueryHook(
|
|
10
|
-
generateMutationHook(
|
|
11
|
-
generateFetcherFetch(
|
|
6
|
+
generateFetcherImplementation(): string;
|
|
7
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
8
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
9
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
10
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
12
11
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FetcherRenderer } from './fetcher.js';
|
|
1
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.js';
|
|
3
2
|
import { ReactQueryVisitor } from './visitor.js';
|
|
4
|
-
export declare class FetchFetcher
|
|
5
|
-
|
|
3
|
+
export declare class FetchFetcher extends FetcherRenderer {
|
|
4
|
+
protected visitor: ReactQueryVisitor;
|
|
6
5
|
constructor(visitor: ReactQueryVisitor);
|
|
7
|
-
|
|
8
|
-
generateInfiniteQueryHook(
|
|
9
|
-
generateQueryHook(
|
|
10
|
-
generateMutationHook(
|
|
11
|
-
generateFetcherFetch(
|
|
6
|
+
generateFetcherImplementation(): string;
|
|
7
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
8
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
9
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
10
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
12
11
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
1
|
import { GraphQlRequest } from './config.cjs';
|
|
3
|
-
import { FetcherRenderer } from './fetcher.cjs';
|
|
2
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.cjs';
|
|
4
3
|
import { ReactQueryVisitor } from './visitor.cjs';
|
|
5
|
-
export declare class GraphQLRequestClientFetcher
|
|
6
|
-
|
|
4
|
+
export declare class GraphQLRequestClientFetcher extends FetcherRenderer {
|
|
5
|
+
protected visitor: ReactQueryVisitor;
|
|
7
6
|
private clientPath;
|
|
8
7
|
constructor(visitor: ReactQueryVisitor, config: GraphQlRequest);
|
|
9
|
-
|
|
10
|
-
generateInfiniteQueryHook(
|
|
11
|
-
generateQueryHook(
|
|
12
|
-
generateMutationHook(
|
|
13
|
-
generateFetcherFetch(
|
|
8
|
+
generateFetcherImplementation(): string;
|
|
9
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
10
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
11
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
12
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
14
13
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
1
|
import { GraphQlRequest } from './config.js';
|
|
3
|
-
import { FetcherRenderer } from './fetcher.js';
|
|
2
|
+
import { FetcherRenderer, type GenerateConfig } from './fetcher.js';
|
|
4
3
|
import { ReactQueryVisitor } from './visitor.js';
|
|
5
|
-
export declare class GraphQLRequestClientFetcher
|
|
6
|
-
|
|
4
|
+
export declare class GraphQLRequestClientFetcher extends FetcherRenderer {
|
|
5
|
+
protected visitor: ReactQueryVisitor;
|
|
7
6
|
private clientPath;
|
|
8
7
|
constructor(visitor: ReactQueryVisitor, config: GraphQlRequest);
|
|
9
|
-
|
|
10
|
-
generateInfiniteQueryHook(
|
|
11
|
-
generateQueryHook(
|
|
12
|
-
generateMutationHook(
|
|
13
|
-
generateFetcherFetch(
|
|
8
|
+
generateFetcherImplementation(): string;
|
|
9
|
+
generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
10
|
+
generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
11
|
+
generateMutationHook(config: GenerateConfig): string;
|
|
12
|
+
generateFetcherFetch(config: GenerateConfig): string;
|
|
14
13
|
}
|
package/typings/fetcher.d.cts
CHANGED
|
@@ -1,8 +1,75 @@
|
|
|
1
1
|
import { OperationDefinitionNode } from 'graphql';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { ReactQueryVisitor } from './visitor.cjs';
|
|
3
|
+
export interface GenerateConfig {
|
|
4
|
+
node: OperationDefinitionNode;
|
|
5
|
+
documentVariableName: string;
|
|
6
|
+
operationName: string;
|
|
7
|
+
operationResultType: string;
|
|
8
|
+
operationVariablesTypes: string;
|
|
9
|
+
hasRequiredVariables: boolean;
|
|
8
10
|
}
|
|
11
|
+
interface GenerateBaseHookConfig {
|
|
12
|
+
implArguments?: string;
|
|
13
|
+
implHookOuter?: string;
|
|
14
|
+
implFetcher: string;
|
|
15
|
+
}
|
|
16
|
+
type ReactQueryMethodMap = {
|
|
17
|
+
[key: string]: {
|
|
18
|
+
getHook: (operationName?: string) => string;
|
|
19
|
+
getOptions: () => string;
|
|
20
|
+
getOtherTypes?: () => {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare abstract class FetcherRenderer {
|
|
26
|
+
protected visitor: ReactQueryVisitor;
|
|
27
|
+
constructor(visitor: ReactQueryVisitor);
|
|
28
|
+
abstract generateFetcherImplementation(): string;
|
|
29
|
+
abstract generateFetcherFetch(config: GenerateConfig): string;
|
|
30
|
+
protected abstract generateQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
31
|
+
protected abstract generateInfiniteQueryHook(config: GenerateConfig, isSuspense?: boolean): string;
|
|
32
|
+
protected abstract generateMutationHook(config: GenerateConfig): string;
|
|
33
|
+
createQueryMethodMap(isSuspense?: boolean): ReactQueryMethodMap;
|
|
34
|
+
protected generateInfiniteQueryHelper(config: GenerateConfig, isSuspense: boolean): {
|
|
35
|
+
generateBaseInfiniteQueryHook: (hookConfig: GenerateBaseHookConfig) => string;
|
|
36
|
+
variables: string;
|
|
37
|
+
options: string;
|
|
38
|
+
};
|
|
39
|
+
protected generateQueryHelper(config: GenerateConfig, isSuspense: boolean): {
|
|
40
|
+
generateBaseQueryHook: (hookConfig: GenerateBaseHookConfig) => string;
|
|
41
|
+
variables: string;
|
|
42
|
+
options: string;
|
|
43
|
+
};
|
|
44
|
+
protected generateMutationHelper(config: GenerateConfig): {
|
|
45
|
+
generateBaseMutationHook: (hookConfig: GenerateBaseHookConfig) => string;
|
|
46
|
+
variables: string;
|
|
47
|
+
options: string;
|
|
48
|
+
};
|
|
49
|
+
protected generateQueryVariablesSignature({ hasRequiredVariables, operationVariablesTypes, }: GenerateConfig): string;
|
|
50
|
+
private generateQueryOptionsSignature;
|
|
51
|
+
private generateInfiniteQueryVariablesSignature;
|
|
52
|
+
private generateInfiniteQueryOptionsSignature;
|
|
53
|
+
generateInfiniteQueryKey(config: GenerateConfig, isSuspense: boolean): string;
|
|
54
|
+
generateInfiniteQueryOutput(config: GenerateConfig, isSuspense?: boolean): {
|
|
55
|
+
hook: string;
|
|
56
|
+
getKey: string;
|
|
57
|
+
rootKey: string;
|
|
58
|
+
};
|
|
59
|
+
generateQueryKey(config: GenerateConfig, isSuspense: boolean): string;
|
|
60
|
+
generateQueryOutput(config: GenerateConfig, isSuspense?: boolean): {
|
|
61
|
+
hook: string;
|
|
62
|
+
document: string;
|
|
63
|
+
getKey: string;
|
|
64
|
+
rootKey: string;
|
|
65
|
+
};
|
|
66
|
+
generateMutationKey({ node }: GenerateConfig): string;
|
|
67
|
+
generateMutationOutput(config: GenerateConfig): {
|
|
68
|
+
hook: string;
|
|
69
|
+
getKey: string;
|
|
70
|
+
};
|
|
71
|
+
private generateInfiniteQueryFormattedParameters;
|
|
72
|
+
private generateQueryFormattedParameters;
|
|
73
|
+
private generateMutationFormattedParameters;
|
|
74
|
+
}
|
|
75
|
+
export {};
|