@graphql-codegen/typescript-react-query 4.0.1-alpha-0814e49cc.0 → 4.0.1
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/package.json +4 -4
- package/typings/config.d.cts +89 -0
- package/typings/fetcher-custom-mapper.d.cts +16 -0
- package/typings/fetcher-fetch-hardcoded.d.cts +16 -0
- package/typings/fetcher-fetch.d.cts +12 -0
- package/typings/fetcher-graphql-request.d.cts +12 -0
- package/typings/fetcher.d.cts +8 -0
- package/typings/index.d.cts +6 -0
- package/typings/variables-generator.d.cts +8 -0
- package/typings/visitor.d.cts +44 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-react-query",
|
|
3
|
-
"version": "4.0.1
|
|
3
|
+
"version": "4.0.1",
|
|
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.
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.12.1
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.6.2",
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.12.1",
|
|
11
11
|
"auto-bind": "~4.0.0",
|
|
12
12
|
"change-case-all": "1.0.14",
|
|
13
13
|
"tslib": "~2.4.0"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"require": {
|
|
31
|
-
"types": "./typings/index.d.
|
|
31
|
+
"types": "./typings/index.d.cts",
|
|
32
32
|
"default": "./cjs/index.js"
|
|
33
33
|
},
|
|
34
34
|
"import": {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
export declare type HardcodedFetch = {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
fetchParams?: string | Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
export declare type CustomFetch = {
|
|
7
|
+
func: string;
|
|
8
|
+
isReactHook?: boolean;
|
|
9
|
+
} | string;
|
|
10
|
+
/**
|
|
11
|
+
* @description This plugin generates `React-Query` Hooks with TypeScript typings.
|
|
12
|
+
*
|
|
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
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export interface ReactQueryRawPluginConfig extends Omit<RawClientSideBasePluginConfig, 'documentMode' | 'noGraphQLTag' | 'gqlImport' | 'documentNodeImport' | 'noExport' | 'importOperationTypesFrom' | 'importDocumentNodeExternallyFrom' | 'useTypeImports' | 'legacyMode'> {
|
|
19
|
+
/**
|
|
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.
|
|
21
|
+
*
|
|
22
|
+
* The following options are available to use:
|
|
23
|
+
*
|
|
24
|
+
* - 'fetch' - requires you to specify endpoint and headers on each call, and uses `fetch` to do the actual http call.
|
|
25
|
+
* - `{ 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.
|
|
26
|
+
* - `file#identifier` - You can use custom fetcher method that should implement the exported `ReactQueryFetcher` interface. Example: `./my-fetcher#myCustomFetcher`.
|
|
27
|
+
* - `graphql-request`: Will generate each hook with `client` argument, where you should pass your own `GraphQLClient` (created from `graphql-request`).
|
|
28
|
+
*/
|
|
29
|
+
fetcher?: 'fetch' | HardcodedFetch | 'graphql-request' | CustomFetch;
|
|
30
|
+
/**
|
|
31
|
+
* @default false
|
|
32
|
+
* @description For each generate query hook adds `document` field with a
|
|
33
|
+
* corresponding GraphQL query. Useful for `queryClient.fetchQuery`.
|
|
34
|
+
* @exampleMarkdown
|
|
35
|
+
* ```ts
|
|
36
|
+
* queryClient.fetchQuery(
|
|
37
|
+
* useUserDetailsQuery.getKey(variables),
|
|
38
|
+
* () => gqlRequest(useUserDetailsQuery.document, variables)
|
|
39
|
+
* )
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
exposeDocument?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* @default false
|
|
45
|
+
* @description For each generate query hook adds getKey(variables: QueryVariables) function. Useful for cache updates. If addInfiniteQuery is true, it will also add a getKey function to each infinite query.
|
|
46
|
+
* @exampleMarkdown
|
|
47
|
+
* ```ts
|
|
48
|
+
* const query = useUserDetailsQuery(...)
|
|
49
|
+
* const key = useUserDetailsQuery.getKey({ id: theUsersId })
|
|
50
|
+
* // use key in a cache update after a mutation
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
exposeQueryKeys?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* @default false
|
|
56
|
+
* @description For each generate mutation hook adds getKey() function. Useful for call outside of functional component.
|
|
57
|
+
* @exampleMarkdown
|
|
58
|
+
* ```ts
|
|
59
|
+
* const mutation = useUserDetailsMutation(...)
|
|
60
|
+
* const key = useUserDetailsMutation.getKey()
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
exposeMutationKeys?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @default false
|
|
66
|
+
* @description For each generate query hook adds `fetcher` field with a corresponding GraphQL query using the fetcher.
|
|
67
|
+
* It is useful for `queryClient.fetchQuery` and `queryClient.prefetchQuery`.
|
|
68
|
+
* @exampleMarkdown
|
|
69
|
+
* ```ts
|
|
70
|
+
* await queryClient.prefetchQuery(userQuery.getKey(), () => userQuery.fetcher())
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
exposeFetcher?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* @default unknown
|
|
76
|
+
* @description Changes the default "TError" generic type.
|
|
77
|
+
*/
|
|
78
|
+
errorType?: string;
|
|
79
|
+
/**
|
|
80
|
+
* @default false
|
|
81
|
+
* @description Adds an Infinite Query along side the standard one
|
|
82
|
+
*/
|
|
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;
|
|
89
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CustomFetch } from './config.cjs';
|
|
2
|
+
import { FetcherRenderer } from './fetcher.cjs';
|
|
3
|
+
import { OperationDefinitionNode } from 'graphql';
|
|
4
|
+
import { ReactQueryVisitor } from './visitor.cjs';
|
|
5
|
+
export declare class CustomMapperFetcher implements FetcherRenderer {
|
|
6
|
+
private visitor;
|
|
7
|
+
private _mapper;
|
|
8
|
+
private _isReactHook;
|
|
9
|
+
constructor(visitor: ReactQueryVisitor, customFetcher: CustomFetch);
|
|
10
|
+
private getFetcherFnName;
|
|
11
|
+
generateFetcherImplementaion(): string;
|
|
12
|
+
generateInfiniteQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
13
|
+
generateQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
14
|
+
generateMutationHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
15
|
+
generateFetcherFetch(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FetcherRenderer } from './fetcher.cjs';
|
|
2
|
+
import { HardcodedFetch } from './config.cjs';
|
|
3
|
+
import { OperationDefinitionNode } from 'graphql';
|
|
4
|
+
import { ReactQueryVisitor } from './visitor.cjs';
|
|
5
|
+
export declare class HardcodedFetchFetcher implements FetcherRenderer {
|
|
6
|
+
private visitor;
|
|
7
|
+
private config;
|
|
8
|
+
constructor(visitor: ReactQueryVisitor, config: HardcodedFetch);
|
|
9
|
+
private getEndpoint;
|
|
10
|
+
private getFetchParams;
|
|
11
|
+
generateFetcherImplementaion(): string;
|
|
12
|
+
generateInfiniteQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
13
|
+
generateQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
14
|
+
generateMutationHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
15
|
+
generateFetcherFetch(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FetcherRenderer } from './fetcher.cjs';
|
|
2
|
+
import { OperationDefinitionNode } from 'graphql';
|
|
3
|
+
import { ReactQueryVisitor } from './visitor.cjs';
|
|
4
|
+
export declare class FetchFetcher implements FetcherRenderer {
|
|
5
|
+
private visitor;
|
|
6
|
+
constructor(visitor: ReactQueryVisitor);
|
|
7
|
+
generateFetcherImplementaion(): string;
|
|
8
|
+
generateInfiniteQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
9
|
+
generateQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
10
|
+
generateMutationHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
11
|
+
generateFetcherFetch(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FetcherRenderer } from './fetcher.cjs';
|
|
2
|
+
import { OperationDefinitionNode } from 'graphql';
|
|
3
|
+
import { ReactQueryVisitor } from './visitor.cjs';
|
|
4
|
+
export declare class GraphQLRequestClientFetcher implements FetcherRenderer {
|
|
5
|
+
private visitor;
|
|
6
|
+
constructor(visitor: ReactQueryVisitor);
|
|
7
|
+
generateFetcherImplementaion(): string;
|
|
8
|
+
generateInfiniteQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
9
|
+
generateQueryHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
10
|
+
generateMutationHook(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
11
|
+
generateFetcherFetch(node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OperationDefinitionNode } from 'graphql';
|
|
2
|
+
export interface FetcherRenderer {
|
|
3
|
+
generateFetcherImplementaion: () => string;
|
|
4
|
+
generateQueryHook: (node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean) => string;
|
|
5
|
+
generateInfiniteQueryHook: (node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean) => string;
|
|
6
|
+
generateMutationHook: (node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean) => string;
|
|
7
|
+
generateFetcherFetch: (node: OperationDefinitionNode, documentVariableName: string, operationName: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean) => string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PluginFunction, PluginValidateFn, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
+
import { ReactQueryRawPluginConfig } from './config.cjs';
|
|
3
|
+
import { ReactQueryVisitor } from './visitor.cjs';
|
|
4
|
+
export declare const plugin: PluginFunction<ReactQueryRawPluginConfig, Types.ComplexPluginOutput>;
|
|
5
|
+
export declare const validate: PluginValidateFn<any>;
|
|
6
|
+
export { ReactQueryVisitor };
|
|
@@ -0,0 +1,8 @@
|
|
|
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 generateQueryKey(node: OperationDefinitionNode, hasRequiredVariables: boolean): string;
|
|
6
|
+
export declare function generateQueryKeyMaker(node: OperationDefinitionNode, operationName: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
7
|
+
export declare function generateMutationKey(node: OperationDefinitionNode): string;
|
|
8
|
+
export declare function generateMutationKeyMaker(node: OperationDefinitionNode, operationName: string): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
|
|
3
|
+
import { FetcherRenderer } from './fetcher.cjs';
|
|
4
|
+
import { ReactQueryRawPluginConfig } from './config.cjs';
|
|
5
|
+
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
6
|
+
export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig {
|
|
7
|
+
errorType: string;
|
|
8
|
+
exposeDocument: boolean;
|
|
9
|
+
exposeQueryKeys: boolean;
|
|
10
|
+
exposeMutationKeys: boolean;
|
|
11
|
+
exposeFetcher: boolean;
|
|
12
|
+
addInfiniteQuery: boolean;
|
|
13
|
+
legacyMode: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ReactQueryMethodMap {
|
|
16
|
+
infiniteQuery: {
|
|
17
|
+
hook: string;
|
|
18
|
+
options: string;
|
|
19
|
+
};
|
|
20
|
+
query: {
|
|
21
|
+
hook: string;
|
|
22
|
+
options: string;
|
|
23
|
+
};
|
|
24
|
+
mutation: {
|
|
25
|
+
hook: string;
|
|
26
|
+
options: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryRawPluginConfig, ReactQueryPluginConfig> {
|
|
30
|
+
protected rawConfig: ReactQueryRawPluginConfig;
|
|
31
|
+
private _externalImportPrefix;
|
|
32
|
+
fetcher: FetcherRenderer;
|
|
33
|
+
reactQueryHookIdentifiersInUse: Set<string>;
|
|
34
|
+
reactQueryOptionsIdentifiersInUse: Set<string>;
|
|
35
|
+
queryMethodMap: ReactQueryMethodMap;
|
|
36
|
+
constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: ReactQueryRawPluginConfig, documents: Types.DocumentFile[]);
|
|
37
|
+
get imports(): Set<string>;
|
|
38
|
+
private createFetcher;
|
|
39
|
+
get hasOperations(): boolean;
|
|
40
|
+
getImports(): string[];
|
|
41
|
+
getFetcherImplementation(): string;
|
|
42
|
+
private _getHookSuffix;
|
|
43
|
+
protected buildOperation(node: OperationDefinitionNode, documentVariableName: string, operationType: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string;
|
|
44
|
+
}
|