@graphql-codegen/typescript-react-query 4.1.0 → 5.0.0-alpha-20230524083052-08ce957b4

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/config.js CHANGED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -34,7 +34,9 @@ class CustomMapperFetcher {
34
34
  this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
35
35
  const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
36
36
  const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
37
- const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
37
+ const implHookOuter = this._isReactHook
38
+ ? `const query = ${typedFetcher}(${documentVariableName})`
39
+ : '';
38
40
  const impl = this._isReactHook
39
41
  ? `(metaData) => query({...variables, ...(metaData.pageParam ?? {})})`
40
42
  : `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ?? {})})()`;
@@ -19,7 +19,9 @@ class HardcodedFetchFetcher {
19
19
  getFetchParams() {
20
20
  let fetchParamsPartial = '';
21
21
  if (this.config.fetchParams) {
22
- const fetchParamsString = typeof this.config.fetchParams === 'string' ? this.config.fetchParams : JSON.stringify(this.config.fetchParams);
22
+ const fetchParamsString = typeof this.config.fetchParams === 'string'
23
+ ? this.config.fetchParams
24
+ : JSON.stringify(this.config.fetchParams);
23
25
  fetchParamsPartial = `\n ...(${fetchParamsString}),`;
24
26
  }
25
27
  return ` method: "POST",${fetchParamsPartial}`;
package/cjs/fetcher.js CHANGED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReactQueryVisitor = exports.validate = exports.plugin = void 0;
4
+ const path_1 = require("path");
4
5
  const graphql_1 = require("graphql");
5
6
  const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
6
7
  const visitor_js_1 = require("./visitor.js");
7
8
  Object.defineProperty(exports, "ReactQueryVisitor", { enumerable: true, get: function () { return visitor_js_1.ReactQueryVisitor; } });
8
- const path_1 = require("path");
9
9
  const plugin = (schema, documents, config) => {
10
10
  const allAst = (0, graphql_1.concatAST)(documents.map(v => v.document));
11
11
  const allFragments = [
@@ -22,12 +22,18 @@ const plugin = (schema, documents, config) => {
22
22
  if (visitor.hasOperations) {
23
23
  return {
24
24
  prepend: [...visitor.getImports(), visitor.getFetcherImplementation()],
25
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
25
+ content: [
26
+ visitor.fragments,
27
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
28
+ ].join('\n'),
26
29
  };
27
30
  }
28
31
  return {
29
32
  prepend: [...visitor.getImports()],
30
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
33
+ content: [
34
+ visitor.fragments,
35
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
36
+ ].join('\n'),
31
37
  };
32
38
  };
33
39
  exports.plugin = plugin;
package/cjs/visitor.js CHANGED
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReactQueryVisitor = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
6
+ const change_case_all_1 = require("change-case-all");
5
7
  const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
- const variables_generator_js_1 = require("./variables-generator.js");
7
8
  const fetcher_custom_mapper_js_1 = require("./fetcher-custom-mapper.js");
9
+ const fetcher_fetch_hardcoded_js_1 = require("./fetcher-fetch-hardcoded.js");
8
10
  const fetcher_fetch_js_1 = require("./fetcher-fetch.js");
9
11
  const fetcher_graphql_request_js_1 = require("./fetcher-graphql-request.js");
10
- const fetcher_fetch_hardcoded_js_1 = require("./fetcher-fetch-hardcoded.js");
11
- const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
12
- const change_case_all_1 = require("change-case-all");
12
+ const variables_generator_js_1 = require("./variables-generator.js");
13
13
  class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
14
14
  constructor(schema, fragments, rawConfig, documents) {
15
15
  super(schema, fragments, rawConfig, {
@@ -39,7 +39,9 @@ class ReactQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
39
39
  options: 'UseMutationOptions',
40
40
  },
41
41
  };
42
- this._externalImportPrefix = this.config.importOperationTypesFrom ? `${this.config.importOperationTypesFrom}.` : '';
42
+ this._externalImportPrefix = this.config.importOperationTypesFrom
43
+ ? `${this.config.importOperationTypesFrom}.`
44
+ : '';
43
45
  this._documents = documents;
44
46
  this.fetcher = this.createFetcher(rawConfig.fetcher || 'fetch');
45
47
  (0, auto_bind_1.default)(this);
package/esm/config.js CHANGED
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +1,5 @@
1
- import { buildMapperImport, parseMapper } from '@graphql-codegen/visitor-plugin-common';
2
- import { generateInfiniteQueryKey, generateMutationKey, generateQueryKey } from './variables-generator.js';
1
+ import { buildMapperImport, parseMapper, } from '@graphql-codegen/visitor-plugin-common';
2
+ import { generateInfiniteQueryKey, generateMutationKey, generateQueryKey, } from './variables-generator.js';
3
3
  export class CustomMapperFetcher {
4
4
  constructor(visitor, customFetcher) {
5
5
  this.visitor = visitor;
@@ -31,7 +31,9 @@ export class CustomMapperFetcher {
31
31
  this.visitor.reactQueryOptionsIdentifiersInUse.add(hookConfig.infiniteQuery.options);
32
32
  const options = `options?: ${hookConfig.infiniteQuery.options}<${operationResultType}, TError, TData>`;
33
33
  const typedFetcher = this.getFetcherFnName(operationResultType, operationVariablesTypes);
34
- const implHookOuter = this._isReactHook ? `const query = ${typedFetcher}(${documentVariableName})` : '';
34
+ const implHookOuter = this._isReactHook
35
+ ? `const query = ${typedFetcher}(${documentVariableName})`
36
+ : '';
35
37
  const impl = this._isReactHook
36
38
  ? `(metaData) => query({...variables, ...(metaData.pageParam ?? {})})`
37
39
  : `(metaData) => ${typedFetcher}(${documentVariableName}, {...variables, ...(metaData.pageParam ?? {})})()`;
@@ -16,7 +16,9 @@ export class HardcodedFetchFetcher {
16
16
  getFetchParams() {
17
17
  let fetchParamsPartial = '';
18
18
  if (this.config.fetchParams) {
19
- const fetchParamsString = typeof this.config.fetchParams === 'string' ? this.config.fetchParams : JSON.stringify(this.config.fetchParams);
19
+ const fetchParamsString = typeof this.config.fetchParams === 'string'
20
+ ? this.config.fetchParams
21
+ : JSON.stringify(this.config.fetchParams);
20
22
  fetchParamsPartial = `\n ...(${fetchParamsString}),`;
21
23
  }
22
24
  return ` method: "POST",${fetchParamsPartial}`;
package/esm/fetcher.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Kind, concatAST } from 'graphql';
1
+ import { extname } from 'path';
2
+ import { concatAST, Kind } from 'graphql';
2
3
  import { oldVisit } from '@graphql-codegen/plugin-helpers';
3
4
  import { ReactQueryVisitor } from './visitor.js';
4
- import { extname } from 'path';
5
5
  export const plugin = (schema, documents, config) => {
6
6
  const allAst = concatAST(documents.map(v => v.document));
7
7
  const allFragments = [
@@ -18,12 +18,18 @@ export const plugin = (schema, documents, config) => {
18
18
  if (visitor.hasOperations) {
19
19
  return {
20
20
  prepend: [...visitor.getImports(), visitor.getFetcherImplementation()],
21
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
21
+ content: [
22
+ visitor.fragments,
23
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
24
+ ].join('\n'),
22
25
  };
23
26
  }
24
27
  return {
25
28
  prepend: [...visitor.getImports()],
26
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
29
+ content: [
30
+ visitor.fragments,
31
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
32
+ ].join('\n'),
27
33
  };
28
34
  };
29
35
  export const validate = async (schema, documents, config, outputFile) => {
package/esm/visitor.js CHANGED
@@ -1,11 +1,11 @@
1
+ import autoBind from 'auto-bind';
2
+ import { pascalCase } from 'change-case-all';
1
3
  import { ClientSideBaseVisitor, DocumentMode, getConfigValue, } from '@graphql-codegen/visitor-plugin-common';
2
- import { generateMutationKeyMaker, generateQueryKeyMaker, generateInfiniteQueryKeyMaker, } from './variables-generator.js';
3
4
  import { CustomMapperFetcher } from './fetcher-custom-mapper.js';
5
+ import { HardcodedFetchFetcher } from './fetcher-fetch-hardcoded.js';
4
6
  import { FetchFetcher } from './fetcher-fetch.js';
5
7
  import { GraphQLRequestClientFetcher } from './fetcher-graphql-request.js';
6
- import { HardcodedFetchFetcher } from './fetcher-fetch-hardcoded.js';
7
- import autoBind from 'auto-bind';
8
- import { pascalCase } from 'change-case-all';
8
+ import { generateInfiniteQueryKeyMaker, generateMutationKeyMaker, generateQueryKeyMaker, } from './variables-generator.js';
9
9
  export class ReactQueryVisitor extends ClientSideBaseVisitor {
10
10
  constructor(schema, fragments, rawConfig, documents) {
11
11
  super(schema, fragments, rawConfig, {
@@ -35,7 +35,9 @@ export class ReactQueryVisitor extends ClientSideBaseVisitor {
35
35
  options: 'UseMutationOptions',
36
36
  },
37
37
  };
38
- this._externalImportPrefix = this.config.importOperationTypesFrom ? `${this.config.importOperationTypesFrom}.` : '';
38
+ this._externalImportPrefix = this.config.importOperationTypesFrom
39
+ ? `${this.config.importOperationTypesFrom}.`
40
+ : '';
39
41
  this._documents = documents;
40
42
  this.fetcher = this.createFetcher(rawConfig.fetcher || 'fetch');
41
43
  autoBind(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-react-query",
3
- "version": "4.1.0",
3
+ "version": "5.0.0-alpha-20230524083052-08ce957b4",
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"
@@ -18,6 +18,9 @@
18
18
  "directory": "packages/plugins/typescript/react-query"
19
19
  },
20
20
  "license": "MIT",
21
+ "engines": {
22
+ "node": ">= 16.0.0"
23
+ },
21
24
  "main": "cjs/index.js",
22
25
  "module": "esm/index.js",
23
26
  "typings": "typings/index.d.ts",
@@ -1,9 +1,9 @@
1
1
  import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
2
- export declare type HardcodedFetch = {
2
+ export type HardcodedFetch = {
3
3
  endpoint: string;
4
4
  fetchParams?: string | Record<string, any>;
5
5
  };
6
- export declare type CustomFetch = {
6
+ export type CustomFetch = {
7
7
  func: string;
8
8
  isReactHook?: boolean;
9
9
  } | string;
@@ -1,9 +1,9 @@
1
1
  import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
2
- export declare type HardcodedFetch = {
2
+ export type HardcodedFetch = {
3
3
  endpoint: string;
4
4
  fetchParams?: string | Record<string, any>;
5
5
  };
6
- export declare type CustomFetch = {
6
+ export type CustomFetch = {
7
7
  func: string;
8
8
  isReactHook?: boolean;
9
9
  } | string;
@@ -1,6 +1,6 @@
1
+ import { OperationDefinitionNode } from 'graphql';
1
2
  import { CustomFetch } from './config.cjs';
2
3
  import { FetcherRenderer } from './fetcher.cjs';
3
- import { OperationDefinitionNode } from 'graphql';
4
4
  import { ReactQueryVisitor } from './visitor.cjs';
5
5
  export declare class CustomMapperFetcher implements FetcherRenderer {
6
6
  private visitor;
@@ -1,6 +1,6 @@
1
+ import { OperationDefinitionNode } from 'graphql';
1
2
  import { CustomFetch } from './config.js';
2
3
  import { FetcherRenderer } from './fetcher.js';
3
- import { OperationDefinitionNode } from 'graphql';
4
4
  import { ReactQueryVisitor } from './visitor.js';
5
5
  export declare class CustomMapperFetcher implements FetcherRenderer {
6
6
  private visitor;
@@ -1,6 +1,6 @@
1
- import { FetcherRenderer } from './fetcher.cjs';
2
- import { HardcodedFetch } from './config.cjs';
3
1
  import { OperationDefinitionNode } from 'graphql';
2
+ import { HardcodedFetch } from './config.cjs';
3
+ import { FetcherRenderer } from './fetcher.cjs';
4
4
  import { ReactQueryVisitor } from './visitor.cjs';
5
5
  export declare class HardcodedFetchFetcher implements FetcherRenderer {
6
6
  private visitor;
@@ -1,6 +1,6 @@
1
- import { FetcherRenderer } from './fetcher.js';
2
- import { HardcodedFetch } from './config.js';
3
1
  import { OperationDefinitionNode } from 'graphql';
2
+ import { HardcodedFetch } from './config.js';
3
+ import { FetcherRenderer } from './fetcher.js';
4
4
  import { ReactQueryVisitor } from './visitor.js';
5
5
  export declare class HardcodedFetchFetcher implements FetcherRenderer {
6
6
  private visitor;
@@ -1,5 +1,5 @@
1
- import { FetcherRenderer } from './fetcher.cjs';
2
1
  import { OperationDefinitionNode } from 'graphql';
2
+ import { FetcherRenderer } from './fetcher.cjs';
3
3
  import { ReactQueryVisitor } from './visitor.cjs';
4
4
  export declare class FetchFetcher implements FetcherRenderer {
5
5
  private visitor;
@@ -1,5 +1,5 @@
1
- import { FetcherRenderer } from './fetcher.js';
2
1
  import { OperationDefinitionNode } from 'graphql';
2
+ import { FetcherRenderer } from './fetcher.js';
3
3
  import { ReactQueryVisitor } from './visitor.js';
4
4
  export declare class FetchFetcher implements FetcherRenderer {
5
5
  private visitor;
@@ -1,5 +1,5 @@
1
- import { FetcherRenderer } from './fetcher.cjs';
2
1
  import { OperationDefinitionNode } from 'graphql';
2
+ import { FetcherRenderer } from './fetcher.cjs';
3
3
  import { ReactQueryVisitor } from './visitor.cjs';
4
4
  export declare class GraphQLRequestClientFetcher implements FetcherRenderer {
5
5
  private visitor;
@@ -1,5 +1,5 @@
1
- import { FetcherRenderer } from './fetcher.js';
2
1
  import { OperationDefinitionNode } from 'graphql';
2
+ import { FetcherRenderer } from './fetcher.js';
3
3
  import { ReactQueryVisitor } from './visitor.js';
4
4
  export declare class GraphQLRequestClientFetcher implements FetcherRenderer {
5
5
  private visitor;
@@ -1,8 +1,8 @@
1
- import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
1
  import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
3
- import { FetcherRenderer } from './fetcher.cjs';
4
- import { ReactQueryRawPluginConfig } from './config.cjs';
5
2
  import { Types } from '@graphql-codegen/plugin-helpers';
3
+ import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
4
+ import { ReactQueryRawPluginConfig } from './config.cjs';
5
+ import { FetcherRenderer } from './fetcher.cjs';
6
6
  export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig {
7
7
  errorType: string;
8
8
  exposeDocument: boolean;
@@ -1,8 +1,8 @@
1
- import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
1
  import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
3
- import { FetcherRenderer } from './fetcher.js';
4
- import { ReactQueryRawPluginConfig } from './config.js';
5
2
  import { Types } from '@graphql-codegen/plugin-helpers';
3
+ import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
4
+ import { ReactQueryRawPluginConfig } from './config.js';
5
+ import { FetcherRenderer } from './fetcher.js';
6
6
  export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig {
7
7
  errorType: string;
8
8
  exposeDocument: boolean;