@graphql-codegen/typescript-rtk-query 2.2.14 → 2.2.16-alpha-2cc8b095b.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/config.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RTKQueryVisitor = exports.validate = exports.plugin = void 0;
4
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
5
+ const graphql_1 = require("graphql");
6
+ const visitor_js_1 = require("./visitor.js");
7
+ Object.defineProperty(exports, "RTKQueryVisitor", { enumerable: true, get: function () { return visitor_js_1.RTKQueryVisitor; } });
8
+ const path_1 = require("path");
9
+ const plugin = (schema, documents, config) => {
10
+ const allAst = (0, graphql_1.concatAST)(documents.map(v => v.document));
11
+ const allFragments = [
12
+ ...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
13
+ node: fragmentDef,
14
+ name: fragmentDef.name.value,
15
+ onType: fragmentDef.typeCondition.name.value,
16
+ isExternal: false,
17
+ })),
18
+ ...(config.externalFragments || []),
19
+ ];
20
+ const visitor = new visitor_js_1.RTKQueryVisitor(schema, allFragments, config, documents);
21
+ const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
22
+ return {
23
+ prepend: visitor.getImports(),
24
+ content: [
25
+ visitor.fragments,
26
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
27
+ visitor.getInjectCall(),
28
+ ].join('\n'),
29
+ };
30
+ };
31
+ exports.plugin = plugin;
32
+ const validate = async (schema, documents, config, outputFile) => {
33
+ if ((0, path_1.extname)(outputFile) !== '.ts' && (0, path_1.extname)(outputFile) !== '.tsx') {
34
+ throw new Error(`Plugin "typescript-rtk-query" requires extension to be ".ts" or ".tsx"!`);
35
+ }
36
+ if (!config.importBaseApiFrom) {
37
+ throw new Error(`You must specify the "importBaseApiFrom" option to use the RTK Query plugin!` + JSON.stringify(config));
38
+ }
39
+ };
40
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,30 +1,24 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- const pluginHelpers = require('@graphql-codegen/plugin-helpers');
8
- const graphql = require('graphql');
9
- const visitorPluginCommon = require('@graphql-codegen/visitor-plugin-common');
10
- const changeCaseAll = require('change-case-all');
11
- const autoBind = _interopDefault(require('auto-bind'));
12
- const path = require('path');
13
-
14
- class RTKQueryVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RTKQueryVisitor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
+ const change_case_all_1 = require("change-case-all");
7
+ const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
8
+ class RTKQueryVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
15
9
  constructor(schema, fragments, rawConfig, documents) {
16
10
  super(schema, fragments, rawConfig, {
17
- documentMode: visitorPluginCommon.DocumentMode.string,
18
- importBaseApiFrom: visitorPluginCommon.getConfigValue(rawConfig.importBaseApiFrom, ''),
19
- exportHooks: visitorPluginCommon.getConfigValue(rawConfig.exportHooks, false),
20
- overrideExisting: visitorPluginCommon.getConfigValue(rawConfig.overrideExisting, ''),
11
+ documentMode: visitor_plugin_common_1.DocumentMode.string,
12
+ importBaseApiFrom: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.importBaseApiFrom, ''),
13
+ exportHooks: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.exportHooks, false),
14
+ overrideExisting: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.overrideExisting, ''),
21
15
  });
22
16
  this.rawConfig = rawConfig;
23
17
  this._endpoints = [];
24
18
  this._hooks = [];
25
19
  this._externalImportPrefix = this.config.importOperationTypesFrom ? `${this.config.importOperationTypesFrom}.` : '';
26
20
  this._documents = documents;
27
- autoBind(this);
21
+ (0, auto_bind_1.default)(this);
28
22
  }
29
23
  get imports() {
30
24
  return this._imports;
@@ -71,8 +65,8 @@ export { injectedRtkApi as api };
71
65
  query: (variables) => ({ document: ${documentVariableName}, variables })
72
66
  }),`);
73
67
  if (this.config.exportHooks) {
74
- this._hooks.push(`use${changeCaseAll.pascalCase(operationName)}Query`);
75
- this._hooks.push(`useLazy${changeCaseAll.pascalCase(operationName)}Query`);
68
+ this._hooks.push(`use${(0, change_case_all_1.pascalCase)(operationName)}Query`);
69
+ this._hooks.push(`useLazy${(0, change_case_all_1.pascalCase)(operationName)}Query`);
76
70
  }
77
71
  }
78
72
  else if (operationType === 'Mutation') {
@@ -81,7 +75,7 @@ export { injectedRtkApi as api };
81
75
  query: (variables) => ({ document: ${documentVariableName}, variables })
82
76
  }),`);
83
77
  if (this.config.exportHooks) {
84
- this._hooks.push(`use${changeCaseAll.pascalCase(operationName)}Mutation`);
78
+ this._hooks.push(`use${(0, change_case_all_1.pascalCase)(operationName)}Mutation`);
85
79
  }
86
80
  }
87
81
  else if (operationType === 'Subscription') {
@@ -91,38 +85,4 @@ export { injectedRtkApi as api };
91
85
  return '';
92
86
  }
93
87
  }
94
-
95
- const plugin = (schema, documents, config) => {
96
- const allAst = graphql.concatAST(documents.map(v => v.document));
97
- const allFragments = [
98
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
99
- node: fragmentDef,
100
- name: fragmentDef.name.value,
101
- onType: fragmentDef.typeCondition.name.value,
102
- isExternal: false,
103
- })),
104
- ...(config.externalFragments || []),
105
- ];
106
- const visitor = new RTKQueryVisitor(schema, allFragments, config, documents);
107
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
108
- return {
109
- prepend: visitor.getImports(),
110
- content: [
111
- visitor.fragments,
112
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
113
- visitor.getInjectCall(),
114
- ].join('\n'),
115
- };
116
- };
117
- const validate = async (schema, documents, config, outputFile) => {
118
- if (path.extname(outputFile) !== '.ts' && path.extname(outputFile) !== '.tsx') {
119
- throw new Error(`Plugin "typescript-rtk-query" requires extension to be ".ts" or ".tsx"!`);
120
- }
121
- if (!config.importBaseApiFrom) {
122
- throw new Error(`You must specify the "importBaseApiFrom" option to use the RTK Query plugin!` + JSON.stringify(config));
123
- }
124
- };
125
-
126
88
  exports.RTKQueryVisitor = RTKQueryVisitor;
127
- exports.plugin = plugin;
128
- exports.validate = validate;
package/esm/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind } from 'graphql';
3
+ import { RTKQueryVisitor } from './visitor.js';
4
+ import { extname } from 'path';
5
+ export const plugin = (schema, documents, config) => {
6
+ const allAst = concatAST(documents.map(v => v.document));
7
+ const allFragments = [
8
+ ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
9
+ node: fragmentDef,
10
+ name: fragmentDef.name.value,
11
+ onType: fragmentDef.typeCondition.name.value,
12
+ isExternal: false,
13
+ })),
14
+ ...(config.externalFragments || []),
15
+ ];
16
+ const visitor = new RTKQueryVisitor(schema, allFragments, config, documents);
17
+ const visitorResult = oldVisit(allAst, { leave: visitor });
18
+ return {
19
+ prepend: visitor.getImports(),
20
+ content: [
21
+ visitor.fragments,
22
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
23
+ visitor.getInjectCall(),
24
+ ].join('\n'),
25
+ };
26
+ };
27
+ export const validate = async (schema, documents, config, outputFile) => {
28
+ if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
29
+ throw new Error(`Plugin "typescript-rtk-query" requires extension to be ".ts" or ".tsx"!`);
30
+ }
31
+ if (!config.importBaseApiFrom) {
32
+ throw new Error(`You must specify the "importBaseApiFrom" option to use the RTK Query plugin!` + JSON.stringify(config));
33
+ }
34
+ };
35
+ export { RTKQueryVisitor };
@@ -1,11 +1,7 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { concatAST, Kind } from 'graphql';
3
- import { ClientSideBaseVisitor, DocumentMode, getConfigValue } from '@graphql-codegen/visitor-plugin-common';
1
+ import { ClientSideBaseVisitor, getConfigValue, DocumentMode, } from '@graphql-codegen/visitor-plugin-common';
4
2
  import { pascalCase } from 'change-case-all';
5
3
  import autoBind from 'auto-bind';
6
- import { extname } from 'path';
7
-
8
- class RTKQueryVisitor extends ClientSideBaseVisitor {
4
+ export class RTKQueryVisitor extends ClientSideBaseVisitor {
9
5
  constructor(schema, fragments, rawConfig, documents) {
10
6
  super(schema, fragments, rawConfig, {
11
7
  documentMode: DocumentMode.string,
@@ -85,36 +81,3 @@ export { injectedRtkApi as api };
85
81
  return '';
86
82
  }
87
83
  }
88
-
89
- const plugin = (schema, documents, config) => {
90
- const allAst = concatAST(documents.map(v => v.document));
91
- const allFragments = [
92
- ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
93
- node: fragmentDef,
94
- name: fragmentDef.name.value,
95
- onType: fragmentDef.typeCondition.name.value,
96
- isExternal: false,
97
- })),
98
- ...(config.externalFragments || []),
99
- ];
100
- const visitor = new RTKQueryVisitor(schema, allFragments, config, documents);
101
- const visitorResult = oldVisit(allAst, { leave: visitor });
102
- return {
103
- prepend: visitor.getImports(),
104
- content: [
105
- visitor.fragments,
106
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
107
- visitor.getInjectCall(),
108
- ].join('\n'),
109
- };
110
- };
111
- const validate = async (schema, documents, config, outputFile) => {
112
- if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
113
- throw new Error(`Plugin "typescript-rtk-query" requires extension to be ".ts" or ".tsx"!`);
114
- }
115
- if (!config.importBaseApiFrom) {
116
- throw new Error(`You must specify the "importBaseApiFrom" option to use the RTK Query plugin!` + JSON.stringify(config));
117
- }
118
- };
119
-
120
- export { RTKQueryVisitor, plugin, validate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-rtk-query",
3
- "version": "2.2.14",
3
+ "version": "2.2.16-alpha-2cc8b095b.0",
4
4
  "description": "GraphQL Code Generator plugin for injecting graphql endpoints into a preconfigured RTK Query api",
5
5
  "peerDependencies": {
6
6
  "@reduxjs/toolkit": "^1.6.0",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@graphql-codegen/plugin-helpers": "^2.4.0",
13
- "@graphql-codegen/visitor-plugin-common": "2.9.1",
13
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-2cc8b095b.0",
14
14
  "auto-bind": "~4.0.0",
15
15
  "change-case-all": "1.0.14",
16
16
  "tslib": "~2.4.0"
@@ -21,21 +21,28 @@
21
21
  "directory": "packages/plugins/typescript/rtk-query"
22
22
  },
23
23
  "license": "MIT",
24
- "main": "index.js",
25
- "module": "index.mjs",
26
- "typings": "index.d.ts",
24
+ "main": "cjs/index.js",
25
+ "module": "esm/index.js",
26
+ "typings": "typings/index.d.ts",
27
27
  "typescript": {
28
- "definition": "index.d.ts"
28
+ "definition": "typings/index.d.ts"
29
29
  },
30
+ "type": "module",
30
31
  "exports": {
31
- "./package.json": "./package.json",
32
32
  ".": {
33
- "require": "./index.js",
34
- "import": "./index.mjs"
33
+ "require": {
34
+ "types": "./typings/index.d.ts",
35
+ "default": "./cjs/index.js"
36
+ },
37
+ "import": {
38
+ "types": "./typings/index.d.ts",
39
+ "default": "./esm/index.js"
40
+ },
41
+ "default": {
42
+ "types": "./typings/index.d.ts",
43
+ "default": "./esm/index.js"
44
+ }
35
45
  },
36
- "./*": {
37
- "require": "./*.js",
38
- "import": "./*.mjs"
39
- }
46
+ "./package.json": "./package.json"
40
47
  }
41
- }
48
+ }
File without changes
@@ -1,6 +1,6 @@
1
1
  import { Types, PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { RTKQueryVisitor } from './visitor';
3
- import { RTKQueryRawPluginConfig } from './config';
2
+ import { RTKQueryVisitor } from './visitor.js';
3
+ import { RTKQueryRawPluginConfig } from './config.js';
4
4
  export declare const plugin: PluginFunction<RTKQueryRawPluginConfig, Types.ComplexPluginOutput>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { RTKQueryVisitor };
@@ -1,6 +1,6 @@
1
1
  import { ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
2
  import { OperationDefinitionNode, GraphQLSchema } from 'graphql';
3
- import { RTKQueryPluginConfig, RTKQueryRawPluginConfig } from './config';
3
+ import { RTKQueryPluginConfig, RTKQueryRawPluginConfig } from './config.js';
4
4
  import { Types } from '@graphql-codegen/plugin-helpers';
5
5
  export declare class RTKQueryVisitor extends ClientSideBaseVisitor<RTKQueryRawPluginConfig, RTKQueryPluginConfig> {
6
6
  protected rawConfig: RTKQueryRawPluginConfig;