@graphql-codegen/typescript-react-apollo 3.3.7 → 4.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 });
package/cjs/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReactApolloVisitor = exports.validate = exports.plugin = void 0;
4
- const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
4
+ const path_1 = require("path");
5
5
  const graphql_1 = require("graphql");
6
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
6
7
  const visitor_js_1 = require("./visitor.js");
7
8
  Object.defineProperty(exports, "ReactApolloVisitor", { enumerable: true, get: function () { return visitor_js_1.ReactApolloVisitor; } });
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 = [
@@ -21,7 +21,10 @@ const plugin = (schema, documents, config) => {
21
21
  const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
22
22
  return {
23
23
  prepend: visitor.getImports(),
24
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
24
+ content: [
25
+ visitor.fragments,
26
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
27
+ ].join('\n'),
25
28
  };
26
29
  };
27
30
  exports.plugin = plugin;
package/cjs/visitor.js CHANGED
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReactApolloVisitor = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
5
  const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
7
- const graphql_1 = require("graphql");
8
6
  const change_case_all_1 = require("change-case-all");
7
+ const graphql_1 = require("graphql");
8
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
9
9
  const APOLLO_CLIENT_3_UNIFIED_PACKAGE = `@apollo/client`;
10
10
  const GROUPED_APOLLO_CLIENT_3_IDENTIFIER = 'Apollo';
11
11
  function hasRequiredVariables(node) {
@@ -21,12 +21,18 @@ class ReactApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
21
21
  withHooks: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withHooks, true),
22
22
  withMutationFn: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withMutationFn, true),
23
23
  withRefetchFn: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withRefetchFn, false),
24
- apolloReactCommonImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactCommonImportFrom, rawConfig.reactApolloVersion === 2 ? '@apollo/react-common' : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
24
+ apolloReactCommonImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactCommonImportFrom, rawConfig.reactApolloVersion === 2
25
+ ? '@apollo/react-common'
26
+ : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
25
27
  apolloReactComponentsImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactComponentsImportFrom, rawConfig.reactApolloVersion === 2
26
28
  ? '@apollo/react-components'
27
29
  : `${APOLLO_CLIENT_3_UNIFIED_PACKAGE}/react/components`),
28
- apolloReactHocImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactHocImportFrom, rawConfig.reactApolloVersion === 2 ? '@apollo/react-hoc' : `${APOLLO_CLIENT_3_UNIFIED_PACKAGE}/react/hoc`),
29
- apolloReactHooksImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactHooksImportFrom, rawConfig.reactApolloVersion === 2 ? '@apollo/react-hooks' : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
30
+ apolloReactHocImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactHocImportFrom, rawConfig.reactApolloVersion === 2
31
+ ? '@apollo/react-hoc'
32
+ : `${APOLLO_CLIENT_3_UNIFIED_PACKAGE}/react/hoc`),
33
+ apolloReactHooksImportFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.apolloReactHooksImportFrom, rawConfig.reactApolloVersion === 2
34
+ ? '@apollo/react-hooks'
35
+ : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
30
36
  reactApolloVersion: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.reactApolloVersion, 3),
31
37
  withResultType: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withResultType, true),
32
38
  withMutationOptionsType: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.withMutationOptionsType, true),
@@ -37,7 +43,9 @@ class ReactApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
37
43
  });
38
44
  this.rawConfig = rawConfig;
39
45
  this.imports = new Set();
40
- this._externalImportPrefix = this.config.importOperationTypesFrom ? `${this.config.importOperationTypesFrom}.` : '';
46
+ this._externalImportPrefix = this.config.importOperationTypesFrom
47
+ ? `${this.config.importOperationTypesFrom}.`
48
+ : '';
41
49
  this._documents = documents;
42
50
  (0, auto_bind_1.default)(this);
43
51
  }
@@ -70,7 +78,8 @@ class ReactApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
70
78
  getApolloReactCommonImport(isTypeImport) {
71
79
  const apolloReactCommonIdentifier = this.getApolloReactCommonIdentifier();
72
80
  return `${this.getImportStatement(isTypeImport &&
73
- (apolloReactCommonIdentifier !== GROUPED_APOLLO_CLIENT_3_IDENTIFIER || this.usesExternalHooksOnly()))} * as ${apolloReactCommonIdentifier} from '${this.config.apolloReactCommonImportFrom}';`;
81
+ (apolloReactCommonIdentifier !== GROUPED_APOLLO_CLIENT_3_IDENTIFIER ||
82
+ this.usesExternalHooksOnly()))} * as ${apolloReactCommonIdentifier} from '${this.config.apolloReactCommonImportFrom}';`;
74
83
  }
75
84
  getApolloReactComponentsImport(isTypeImport) {
76
85
  return `${this.getImportStatement(isTypeImport)} * as ApolloReactComponents from '${this.config.apolloReactComponentsImportFrom}';`;
@@ -104,7 +113,8 @@ class ReactApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
104
113
  _buildHocProps(operationName, operationType) {
105
114
  const typeVariableName = this._externalImportPrefix +
106
115
  this.convertName(operationName + (0, change_case_all_1.pascalCase)(operationType) + this._parsedConfig.operationResultSuffix);
107
- const variablesVarName = this._externalImportPrefix + this.convertName(operationName + (0, change_case_all_1.pascalCase)(operationType) + 'Variables');
116
+ const variablesVarName = this._externalImportPrefix +
117
+ this.convertName(operationName + (0, change_case_all_1.pascalCase)(operationType) + 'Variables');
108
118
  const typeArgs = `<${typeVariableName}, ${variablesVarName}>`;
109
119
  if (operationType === 'mutation') {
110
120
  this.imports.add(this.getApolloReactCommonImport(true));
@@ -230,7 +240,9 @@ class ReactApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
230
240
  if (this.config.addDocBlocks) {
231
241
  hookFns.unshift(this._buildHooksJSDoc(node, operationName, operationType));
232
242
  }
233
- const hookResults = [`export type ${operationName}HookResult = ReturnType<typeof use${operationName}>;`];
243
+ const hookResults = [
244
+ `export type ${operationName}HookResult = ReturnType<typeof use${operationName}>;`,
245
+ ];
234
246
  if (operationType === 'Query') {
235
247
  const lazyOperationName = this.convertName(nodeName, {
236
248
  suffix: (0, change_case_all_1.pascalCase)('LazyQuery'),
@@ -327,7 +339,9 @@ class ReactApolloVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
327
339
  const refetchFn = this.config.withRefetchFn
328
340
  ? this._buildRefetchFn(node, documentVariableName, operationType, operationVariablesTypes)
329
341
  : null;
330
- return [mutationFn, component, hoc, hooks, resultType, mutationOptionsType, refetchFn].filter(a => a).join('\n');
342
+ return [mutationFn, component, hoc, hooks, resultType, mutationOptionsType, refetchFn]
343
+ .filter(a => a)
344
+ .join('\n');
331
345
  }
332
346
  }
333
347
  exports.ReactApolloVisitor = ReactApolloVisitor;
package/esm/config.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
1
+ import { extname } from 'path';
2
2
  import { concatAST, Kind } from 'graphql';
3
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
3
4
  import { ReactApolloVisitor } 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 = [
@@ -17,7 +17,10 @@ export const plugin = (schema, documents, config) => {
17
17
  const visitorResult = oldVisit(allAst, { leave: visitor });
18
18
  return {
19
19
  prepend: visitor.getImports(),
20
- content: [visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\n'),
20
+ content: [
21
+ visitor.fragments,
22
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
23
+ ].join('\n'),
21
24
  };
22
25
  };
23
26
  export const validate = async (schema, documents, config, outputFile) => {
package/esm/visitor.js CHANGED
@@ -1,7 +1,7 @@
1
- import { ClientSideBaseVisitor, getConfigValue, OMIT_TYPE, DocumentMode, } from '@graphql-codegen/visitor-plugin-common';
2
1
  import autoBind from 'auto-bind';
2
+ import { camelCase, pascalCase } from 'change-case-all';
3
3
  import { Kind } from 'graphql';
4
- import { pascalCase, camelCase } from 'change-case-all';
4
+ import { ClientSideBaseVisitor, DocumentMode, getConfigValue, OMIT_TYPE, } from '@graphql-codegen/visitor-plugin-common';
5
5
  const APOLLO_CLIENT_3_UNIFIED_PACKAGE = `@apollo/client`;
6
6
  const GROUPED_APOLLO_CLIENT_3_IDENTIFIER = 'Apollo';
7
7
  function hasRequiredVariables(node) {
@@ -17,12 +17,18 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor {
17
17
  withHooks: getConfigValue(rawConfig.withHooks, true),
18
18
  withMutationFn: getConfigValue(rawConfig.withMutationFn, true),
19
19
  withRefetchFn: getConfigValue(rawConfig.withRefetchFn, false),
20
- apolloReactCommonImportFrom: getConfigValue(rawConfig.apolloReactCommonImportFrom, rawConfig.reactApolloVersion === 2 ? '@apollo/react-common' : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
20
+ apolloReactCommonImportFrom: getConfigValue(rawConfig.apolloReactCommonImportFrom, rawConfig.reactApolloVersion === 2
21
+ ? '@apollo/react-common'
22
+ : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
21
23
  apolloReactComponentsImportFrom: getConfigValue(rawConfig.apolloReactComponentsImportFrom, rawConfig.reactApolloVersion === 2
22
24
  ? '@apollo/react-components'
23
25
  : `${APOLLO_CLIENT_3_UNIFIED_PACKAGE}/react/components`),
24
- apolloReactHocImportFrom: getConfigValue(rawConfig.apolloReactHocImportFrom, rawConfig.reactApolloVersion === 2 ? '@apollo/react-hoc' : `${APOLLO_CLIENT_3_UNIFIED_PACKAGE}/react/hoc`),
25
- apolloReactHooksImportFrom: getConfigValue(rawConfig.apolloReactHooksImportFrom, rawConfig.reactApolloVersion === 2 ? '@apollo/react-hooks' : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
26
+ apolloReactHocImportFrom: getConfigValue(rawConfig.apolloReactHocImportFrom, rawConfig.reactApolloVersion === 2
27
+ ? '@apollo/react-hoc'
28
+ : `${APOLLO_CLIENT_3_UNIFIED_PACKAGE}/react/hoc`),
29
+ apolloReactHooksImportFrom: getConfigValue(rawConfig.apolloReactHooksImportFrom, rawConfig.reactApolloVersion === 2
30
+ ? '@apollo/react-hooks'
31
+ : APOLLO_CLIENT_3_UNIFIED_PACKAGE),
26
32
  reactApolloVersion: getConfigValue(rawConfig.reactApolloVersion, 3),
27
33
  withResultType: getConfigValue(rawConfig.withResultType, true),
28
34
  withMutationOptionsType: getConfigValue(rawConfig.withMutationOptionsType, true),
@@ -33,7 +39,9 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor {
33
39
  });
34
40
  this.rawConfig = rawConfig;
35
41
  this.imports = new Set();
36
- this._externalImportPrefix = this.config.importOperationTypesFrom ? `${this.config.importOperationTypesFrom}.` : '';
42
+ this._externalImportPrefix = this.config.importOperationTypesFrom
43
+ ? `${this.config.importOperationTypesFrom}.`
44
+ : '';
37
45
  this._documents = documents;
38
46
  autoBind(this);
39
47
  }
@@ -66,7 +74,8 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor {
66
74
  getApolloReactCommonImport(isTypeImport) {
67
75
  const apolloReactCommonIdentifier = this.getApolloReactCommonIdentifier();
68
76
  return `${this.getImportStatement(isTypeImport &&
69
- (apolloReactCommonIdentifier !== GROUPED_APOLLO_CLIENT_3_IDENTIFIER || this.usesExternalHooksOnly()))} * as ${apolloReactCommonIdentifier} from '${this.config.apolloReactCommonImportFrom}';`;
77
+ (apolloReactCommonIdentifier !== GROUPED_APOLLO_CLIENT_3_IDENTIFIER ||
78
+ this.usesExternalHooksOnly()))} * as ${apolloReactCommonIdentifier} from '${this.config.apolloReactCommonImportFrom}';`;
70
79
  }
71
80
  getApolloReactComponentsImport(isTypeImport) {
72
81
  return `${this.getImportStatement(isTypeImport)} * as ApolloReactComponents from '${this.config.apolloReactComponentsImportFrom}';`;
@@ -100,7 +109,8 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor {
100
109
  _buildHocProps(operationName, operationType) {
101
110
  const typeVariableName = this._externalImportPrefix +
102
111
  this.convertName(operationName + pascalCase(operationType) + this._parsedConfig.operationResultSuffix);
103
- const variablesVarName = this._externalImportPrefix + this.convertName(operationName + pascalCase(operationType) + 'Variables');
112
+ const variablesVarName = this._externalImportPrefix +
113
+ this.convertName(operationName + pascalCase(operationType) + 'Variables');
104
114
  const typeArgs = `<${typeVariableName}, ${variablesVarName}>`;
105
115
  if (operationType === 'mutation') {
106
116
  this.imports.add(this.getApolloReactCommonImport(true));
@@ -226,7 +236,9 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor {
226
236
  if (this.config.addDocBlocks) {
227
237
  hookFns.unshift(this._buildHooksJSDoc(node, operationName, operationType));
228
238
  }
229
- const hookResults = [`export type ${operationName}HookResult = ReturnType<typeof use${operationName}>;`];
239
+ const hookResults = [
240
+ `export type ${operationName}HookResult = ReturnType<typeof use${operationName}>;`,
241
+ ];
230
242
  if (operationType === 'Query') {
231
243
  const lazyOperationName = this.convertName(nodeName, {
232
244
  suffix: pascalCase('LazyQuery'),
@@ -323,6 +335,8 @@ export class ReactApolloVisitor extends ClientSideBaseVisitor {
323
335
  const refetchFn = this.config.withRefetchFn
324
336
  ? this._buildRefetchFn(node, documentVariableName, operationType, operationVariablesTypes)
325
337
  : null;
326
- return [mutationFn, component, hoc, hooks, resultType, mutationOptionsType, refetchFn].filter(a => a).join('\n');
338
+ return [mutationFn, component, hoc, hooks, resultType, mutationOptionsType, refetchFn]
339
+ .filter(a => a)
340
+ .join('\n');
327
341
  }
328
342
  }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-react-apollo",
3
- "version": "3.3.7",
3
+ "version": "4.0.0-alpha-20230524083052-08ce957b4",
4
4
  "description": "GraphQL Code Generator plugin for generating a ready-to-use React Components/HOC/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": "^2.7.2",
10
+ "@graphql-codegen/plugin-helpers": "^3.0.0",
11
11
  "@graphql-codegen/visitor-plugin-common": "2.13.1",
12
12
  "auto-bind": "~4.0.0",
13
- "change-case-all": "1.0.14",
13
+ "change-case-all": "1.0.15",
14
14
  "tslib": "~2.4.0"
15
15
  },
16
16
  "repository": {
@@ -19,6 +19,9 @@
19
19
  "directory": "packages/plugins/typescript/react-apollo"
20
20
  },
21
21
  "license": "MIT",
22
+ "engines": {
23
+ "node": ">= 16.0.0"
24
+ },
22
25
  "main": "cjs/index.js",
23
26
  "module": "esm/index.js",
24
27
  "typings": "typings/index.d.ts",
@@ -1,6 +1,6 @@
1
- import { Types, PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { ReactApolloVisitor } from './visitor.cjs';
1
+ import { PluginFunction, PluginValidateFn, Types } from '@graphql-codegen/plugin-helpers';
3
2
  import { ReactApolloRawPluginConfig } from './config.cjs';
3
+ import { ReactApolloVisitor } from './visitor.cjs';
4
4
  export declare const plugin: PluginFunction<ReactApolloRawPluginConfig, Types.ComplexPluginOutput>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { ReactApolloVisitor };
@@ -1,6 +1,6 @@
1
- import { Types, PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { ReactApolloVisitor } from './visitor.js';
1
+ import { PluginFunction, PluginValidateFn, Types } from '@graphql-codegen/plugin-helpers';
3
2
  import { ReactApolloRawPluginConfig } from './config.js';
3
+ import { ReactApolloVisitor } from './visitor.js';
4
4
  export declare const plugin: PluginFunction<ReactApolloRawPluginConfig, Types.ComplexPluginOutput>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { ReactApolloVisitor };
@@ -1,7 +1,7 @@
1
- import { ClientSideBaseVisitor, ClientSideBasePluginConfig, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
- import { ReactApolloRawPluginConfig } from './config.cjs';
3
- import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
1
+ import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
4
2
  import { Types } from '@graphql-codegen/plugin-helpers';
3
+ import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
4
+ import { ReactApolloRawPluginConfig } from './config.cjs';
5
5
  export interface ReactApolloPluginConfig extends ClientSideBasePluginConfig {
6
6
  withComponent: boolean;
7
7
  withHOC: boolean;
@@ -1,7 +1,7 @@
1
- import { ClientSideBaseVisitor, ClientSideBasePluginConfig, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
- import { ReactApolloRawPluginConfig } from './config.js';
3
- import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
1
+ import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
4
2
  import { Types } from '@graphql-codegen/plugin-helpers';
3
+ import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
4
+ import { ReactApolloRawPluginConfig } from './config.js';
5
5
  export interface ReactApolloPluginConfig extends ClientSideBasePluginConfig {
6
6
  withComponent: boolean;
7
7
  withHOC: boolean;