@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/typings/fetcher.d.ts
CHANGED
|
@@ -1,8 +1,75 @@
|
|
|
1
1
|
import { OperationDefinitionNode } from 'graphql';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { ReactQueryVisitor } from './visitor.js';
|
|
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 {};
|
package/typings/visitor.d.cts
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
1
|
import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
|
|
2
2
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
-
import { ReactQueryRawPluginConfig } from './config.cjs';
|
|
4
|
+
import { BaseReactQueryPluginConfig, ReactQueryRawPluginConfig } from './config.cjs';
|
|
5
5
|
import { FetcherRenderer } from './fetcher.cjs';
|
|
6
|
-
export
|
|
7
|
-
errorType: string;
|
|
8
|
-
exposeDocument: boolean;
|
|
9
|
-
exposeQueryKeys: boolean;
|
|
10
|
-
exposeQueryRootKeys: boolean;
|
|
11
|
-
exposeMutationKeys: boolean;
|
|
12
|
-
exposeFetcher: boolean;
|
|
13
|
-
addInfiniteQuery: boolean;
|
|
14
|
-
legacyMode: boolean;
|
|
15
|
-
reactQueryImportFrom?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface ReactQueryMethodMap {
|
|
18
|
-
infiniteQuery: {
|
|
19
|
-
hook: string;
|
|
20
|
-
options: string;
|
|
21
|
-
};
|
|
22
|
-
query: {
|
|
23
|
-
hook: string;
|
|
24
|
-
options: string;
|
|
25
|
-
};
|
|
26
|
-
mutation: {
|
|
27
|
-
hook: string;
|
|
28
|
-
options: string;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
6
|
+
export type ReactQueryPluginConfig = BaseReactQueryPluginConfig & ClientSideBasePluginConfig;
|
|
31
7
|
export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryRawPluginConfig, ReactQueryPluginConfig> {
|
|
32
8
|
protected rawConfig: ReactQueryRawPluginConfig;
|
|
33
9
|
private _externalImportPrefix;
|
|
34
10
|
fetcher: FetcherRenderer;
|
|
35
11
|
reactQueryHookIdentifiersInUse: Set<string>;
|
|
36
12
|
reactQueryOptionsIdentifiersInUse: Set<string>;
|
|
37
|
-
queryMethodMap: ReactQueryMethodMap;
|
|
38
13
|
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: ReactQueryRawPluginConfig, documents: Types.DocumentFile[]);
|
|
39
14
|
get imports(): Set<string>;
|
|
40
15
|
private createFetcher;
|
package/typings/visitor.d.ts
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
1
|
import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
|
|
2
2
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
-
import { ReactQueryRawPluginConfig } from './config.js';
|
|
4
|
+
import { BaseReactQueryPluginConfig, ReactQueryRawPluginConfig } from './config.js';
|
|
5
5
|
import { FetcherRenderer } from './fetcher.js';
|
|
6
|
-
export
|
|
7
|
-
errorType: string;
|
|
8
|
-
exposeDocument: boolean;
|
|
9
|
-
exposeQueryKeys: boolean;
|
|
10
|
-
exposeQueryRootKeys: boolean;
|
|
11
|
-
exposeMutationKeys: boolean;
|
|
12
|
-
exposeFetcher: boolean;
|
|
13
|
-
addInfiniteQuery: boolean;
|
|
14
|
-
legacyMode: boolean;
|
|
15
|
-
reactQueryImportFrom?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface ReactQueryMethodMap {
|
|
18
|
-
infiniteQuery: {
|
|
19
|
-
hook: string;
|
|
20
|
-
options: string;
|
|
21
|
-
};
|
|
22
|
-
query: {
|
|
23
|
-
hook: string;
|
|
24
|
-
options: string;
|
|
25
|
-
};
|
|
26
|
-
mutation: {
|
|
27
|
-
hook: string;
|
|
28
|
-
options: string;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
6
|
+
export type ReactQueryPluginConfig = BaseReactQueryPluginConfig & ClientSideBasePluginConfig;
|
|
31
7
|
export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryRawPluginConfig, ReactQueryPluginConfig> {
|
|
32
8
|
protected rawConfig: ReactQueryRawPluginConfig;
|
|
33
9
|
private _externalImportPrefix;
|
|
34
10
|
fetcher: FetcherRenderer;
|
|
35
11
|
reactQueryHookIdentifiersInUse: Set<string>;
|
|
36
12
|
reactQueryOptionsIdentifiersInUse: Set<string>;
|
|
37
|
-
queryMethodMap: ReactQueryMethodMap;
|
|
38
13
|
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: ReactQueryRawPluginConfig, documents: Types.DocumentFile[]);
|
|
39
14
|
get imports(): Set<string>;
|
|
40
15
|
private createFetcher;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateMutationKeyMaker = exports.generateMutationKey = exports.generateQueryRootKeyMaker = exports.generateQueryKeyMaker = exports.generateQueryKey = exports.generateInfiniteQueryRootKeyMaker = exports.generateInfiniteQueryKeyMaker = exports.generateInfiniteQueryKey = exports.generateQueryVariablesSignature = void 0;
|
|
4
|
-
function generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes) {
|
|
5
|
-
return `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
6
|
-
}
|
|
7
|
-
exports.generateQueryVariablesSignature = generateQueryVariablesSignature;
|
|
8
|
-
function generateInfiniteQueryKey(node, hasRequiredVariables) {
|
|
9
|
-
if (hasRequiredVariables)
|
|
10
|
-
return `['${node.name.value}.infinite', variables]`;
|
|
11
|
-
return `variables === undefined ? ['${node.name.value}.infinite'] : ['${node.name.value}.infinite', variables]`;
|
|
12
|
-
}
|
|
13
|
-
exports.generateInfiniteQueryKey = generateInfiniteQueryKey;
|
|
14
|
-
function generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables) {
|
|
15
|
-
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
16
|
-
return `\nuseInfinite${operationName}.getKey = (${signature}) => ${generateInfiniteQueryKey(node, hasRequiredVariables)};\n`;
|
|
17
|
-
}
|
|
18
|
-
exports.generateInfiniteQueryKeyMaker = generateInfiniteQueryKeyMaker;
|
|
19
|
-
function generateInfiniteQueryRootKeyMaker(node, operationName) {
|
|
20
|
-
return `\nuseInfinite${operationName}.rootKey = '${node.name.value}.infinite';\n`;
|
|
21
|
-
}
|
|
22
|
-
exports.generateInfiniteQueryRootKeyMaker = generateInfiniteQueryRootKeyMaker;
|
|
23
|
-
function generateQueryKey(node, hasRequiredVariables) {
|
|
24
|
-
if (hasRequiredVariables)
|
|
25
|
-
return `['${node.name.value}', variables]`;
|
|
26
|
-
return `variables === undefined ? ['${node.name.value}'] : ['${node.name.value}', variables]`;
|
|
27
|
-
}
|
|
28
|
-
exports.generateQueryKey = generateQueryKey;
|
|
29
|
-
function generateQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables) {
|
|
30
|
-
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
31
|
-
return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
|
|
32
|
-
}
|
|
33
|
-
exports.generateQueryKeyMaker = generateQueryKeyMaker;
|
|
34
|
-
function generateQueryRootKeyMaker(node, operationName) {
|
|
35
|
-
return `\nuse${operationName}.rootKey = '${node.name.value}';\n`;
|
|
36
|
-
}
|
|
37
|
-
exports.generateQueryRootKeyMaker = generateQueryRootKeyMaker;
|
|
38
|
-
function generateMutationKey(node) {
|
|
39
|
-
return `['${node.name.value}']`;
|
|
40
|
-
}
|
|
41
|
-
exports.generateMutationKey = generateMutationKey;
|
|
42
|
-
function generateMutationKeyMaker(node, operationName) {
|
|
43
|
-
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
|
|
44
|
-
}
|
|
45
|
-
exports.generateMutationKeyMaker = generateMutationKeyMaker;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export function generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes) {
|
|
2
|
-
return `variables${hasRequiredVariables ? '' : '?'}: ${operationVariablesTypes}`;
|
|
3
|
-
}
|
|
4
|
-
export function generateInfiniteQueryKey(node, hasRequiredVariables) {
|
|
5
|
-
if (hasRequiredVariables)
|
|
6
|
-
return `['${node.name.value}.infinite', variables]`;
|
|
7
|
-
return `variables === undefined ? ['${node.name.value}.infinite'] : ['${node.name.value}.infinite', variables]`;
|
|
8
|
-
}
|
|
9
|
-
export function generateInfiniteQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables) {
|
|
10
|
-
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
11
|
-
return `\nuseInfinite${operationName}.getKey = (${signature}) => ${generateInfiniteQueryKey(node, hasRequiredVariables)};\n`;
|
|
12
|
-
}
|
|
13
|
-
export function generateInfiniteQueryRootKeyMaker(node, operationName) {
|
|
14
|
-
return `\nuseInfinite${operationName}.rootKey = '${node.name.value}.infinite';\n`;
|
|
15
|
-
}
|
|
16
|
-
export function generateQueryKey(node, hasRequiredVariables) {
|
|
17
|
-
if (hasRequiredVariables)
|
|
18
|
-
return `['${node.name.value}', variables]`;
|
|
19
|
-
return `variables === undefined ? ['${node.name.value}'] : ['${node.name.value}', variables]`;
|
|
20
|
-
}
|
|
21
|
-
export function generateQueryKeyMaker(node, operationName, operationVariablesTypes, hasRequiredVariables) {
|
|
22
|
-
const signature = generateQueryVariablesSignature(hasRequiredVariables, operationVariablesTypes);
|
|
23
|
-
return `\nuse${operationName}.getKey = (${signature}) => ${generateQueryKey(node, hasRequiredVariables)};\n`;
|
|
24
|
-
}
|
|
25
|
-
export function generateQueryRootKeyMaker(node, operationName) {
|
|
26
|
-
return `\nuse${operationName}.rootKey = '${node.name.value}';\n`;
|
|
27
|
-
}
|
|
28
|
-
export function generateMutationKey(node) {
|
|
29
|
-
return `['${node.name.value}']`;
|
|
30
|
-
}
|
|
31
|
-
export function generateMutationKeyMaker(node, operationName) {
|
|
32
|
-
return `\nuse${operationName}.getKey = () => ${generateMutationKey(node)};\n`;
|
|
33
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
|
-
export declare function generateQueryVariablesSignature(hasRequiredVariables: boolean, operationVariablesTypes: string): string;
|
|
3
|
-
export declare function generateInfiniteQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
4
|
-
export declare function generateInfiniteQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
5
|
-
export declare function generateInfiniteQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
6
|
-
export declare function generateQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
7
|
-
export declare function generateQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
8
|
-
export declare function generateQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
9
|
-
export declare function generateMutationKey(node: OperationDefinitionNode): string;
|
|
10
|
-
export declare function generateMutationKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { OperationDefinitionNode } from 'graphql';
|
|
2
|
-
export declare function generateQueryVariablesSignature(hasRequiredVariables: boolean, operationVariablesTypes: string): string;
|
|
3
|
-
export declare function generateInfiniteQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
4
|
-
export declare function generateInfiniteQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
5
|
-
export declare function generateInfiniteQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
6
|
-
export declare function generateQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
7
|
-
export declare function generateQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
8
|
-
export declare function generateQueryRootKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
9
|
-
export declare function generateMutationKey(node: OperationDefinitionNode): string;
|
|
10
|
-
export declare function generateMutationKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|