@graphql-codegen/typescript-graphql-request 4.4.10-alpha-7a65ba05d.0 → 4.4.12-alpha-5d16266dd.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,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphQLRequestVisitor = 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, "GraphQLRequestVisitor", { enumerable: true, get: function () { return visitor_js_1.GraphQLRequestVisitor; } });
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.GraphQLRequestVisitor(schema, allFragments, config);
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.sdkContent,
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') {
34
+ throw new Error(`Plugin "typescript-graphql-request" requires extension to be ".ts"!`);
35
+ }
36
+ };
37
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,33 +1,26 @@
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 autoBind = _interopDefault(require('auto-bind'));
11
- const path = require('path');
12
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphQLRequestVisitor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
6
+ const auto_bind_1 = tslib_1.__importDefault(require("auto-bind"));
7
+ const graphql_1 = require("graphql");
13
8
  const additionalExportedTypes = `
14
9
  export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
15
10
  `;
16
- class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
11
+ class GraphQLRequestVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
17
12
  constructor(schema, fragments, rawConfig) {
18
13
  super(schema, fragments, rawConfig, {
19
- rawRequest: visitorPluginCommon.getConfigValue(rawConfig.rawRequest, false),
20
- extensionsType: visitorPluginCommon.getConfigValue(rawConfig.extensionsType, 'any'),
14
+ rawRequest: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.rawRequest, false),
15
+ extensionsType: (0, visitor_plugin_common_1.getConfigValue)(rawConfig.extensionsType, 'any'),
21
16
  });
22
17
  this._operationsToInclude = [];
23
- autoBind(this);
18
+ (0, auto_bind_1.default)(this);
24
19
  const typeImport = this.config.useTypeImports ? 'import type' : 'import';
25
20
  this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);
26
21
  this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);
27
- if (this.config.rawRequest) {
28
- if (this.config.documentMode !== visitorPluginCommon.DocumentMode.string) {
29
- this._additionalImports.push(`import { print } from 'graphql'`);
30
- }
22
+ if (this.config.rawRequest && this.config.documentMode !== visitor_plugin_common_1.DocumentMode.string) {
23
+ this._additionalImports.push(`import { print } from 'graphql'`);
31
24
  }
32
25
  }
33
26
  OperationDefinition(node) {
@@ -35,7 +28,7 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
35
28
  const operationName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;
36
29
  if (!operationName) {
37
30
  // eslint-disable-next-line no-console
38
- console.warn(`Anonymous GraphQL operation was ignored in "typescript-graphql-request", please make sure to name your operation: `, graphql.print(node));
31
+ console.warn(`Anonymous GraphQL operation was ignored in "typescript-graphql-request", please make sure to name your operation: `, (0, graphql_1.print)(node));
39
32
  return null;
40
33
  }
41
34
  return super.OperationDefinition(node);
@@ -51,7 +44,7 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
51
44
  return null;
52
45
  }
53
46
  getDocumentNodeVariable(documentVariableName) {
54
- return this.config.documentMode === visitorPluginCommon.DocumentMode.external
47
+ return this.config.documentMode === visitor_plugin_common_1.DocumentMode.external
55
48
  ? `Operations.${documentVariableName}`
56
49
  : documentVariableName;
57
50
  }
@@ -63,11 +56,11 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
63
56
  const operationName = o.node.name.value;
64
57
  const optionalVariables = !o.node.variableDefinitions ||
65
58
  o.node.variableDefinitions.length === 0 ||
66
- o.node.variableDefinitions.every(v => v.type.kind !== graphql.Kind.NON_NULL_TYPE || v.defaultValue);
59
+ o.node.variableDefinitions.every(v => v.type.kind !== graphql_1.Kind.NON_NULL_TYPE || v.defaultValue);
67
60
  const docVarName = this.getDocumentNodeVariable(o.documentVariableName);
68
61
  if (this.config.rawRequest) {
69
62
  let docArg = docVarName;
70
- if (this.config.documentMode !== visitorPluginCommon.DocumentMode.string) {
63
+ if (this.config.documentMode !== visitor_plugin_common_1.DocumentMode.string) {
71
64
  docArg = `${docVarName}String`;
72
65
  extraVariables.push(`const ${docArg} = print(${docVarName});`);
73
66
  }
@@ -80,7 +73,7 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
80
73
  }`;
81
74
  })
82
75
  .filter(Boolean)
83
- .map(s => visitorPluginCommon.indentMultiline(s, 2));
76
+ .map(s => (0, visitor_plugin_common_1.indentMultiline)(s, 2));
84
77
  return `${additionalExportedTypes}
85
78
 
86
79
  const defaultWrapper: SdkFunctionWrapper = (action, _operationName, _operationType) => action();
@@ -93,35 +86,4 @@ ${allPossibleActions.join(',\n')}
93
86
  export type Sdk = ReturnType<typeof getSdk>;`;
94
87
  }
95
88
  }
96
-
97
- const plugin = (schema, documents, config) => {
98
- const allAst = graphql.concatAST(documents.map(v => v.document));
99
- const allFragments = [
100
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
101
- node: fragmentDef,
102
- name: fragmentDef.name.value,
103
- onType: fragmentDef.typeCondition.name.value,
104
- isExternal: false,
105
- })),
106
- ...(config.externalFragments || []),
107
- ];
108
- const visitor = new GraphQLRequestVisitor(schema, allFragments, config);
109
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
110
- return {
111
- prepend: visitor.getImports(),
112
- content: [
113
- visitor.fragments,
114
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
115
- visitor.sdkContent,
116
- ].join('\n'),
117
- };
118
- };
119
- const validate = async (schema, documents, config, outputFile) => {
120
- if (path.extname(outputFile) !== '.ts') {
121
- throw new Error(`Plugin "typescript-graphql-request" requires extension to be ".ts"!`);
122
- }
123
- };
124
-
125
89
  exports.GraphQLRequestVisitor = GraphQLRequestVisitor;
126
- exports.plugin = plugin;
127
- exports.validate = validate;
package/esm/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,32 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind } from 'graphql';
3
+ import { GraphQLRequestVisitor } 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 GraphQLRequestVisitor(schema, allFragments, config);
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.sdkContent,
24
+ ].join('\n'),
25
+ };
26
+ };
27
+ export const validate = async (schema, documents, config, outputFile) => {
28
+ if (extname(outputFile) !== '.ts') {
29
+ throw new Error(`Plugin "typescript-graphql-request" requires extension to be ".ts"!`);
30
+ }
31
+ };
32
+ export { GraphQLRequestVisitor };
@@ -1,13 +1,10 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { print, Kind, concatAST } from 'graphql';
3
- import { ClientSideBaseVisitor, getConfigValue, DocumentMode, indentMultiline } from '@graphql-codegen/visitor-plugin-common';
1
+ import { ClientSideBaseVisitor, DocumentMode, getConfigValue, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';
4
2
  import autoBind from 'auto-bind';
5
- import { extname } from 'path';
6
-
3
+ import { Kind, print } from 'graphql';
7
4
  const additionalExportedTypes = `
8
5
  export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
9
6
  `;
10
- class GraphQLRequestVisitor extends ClientSideBaseVisitor {
7
+ export class GraphQLRequestVisitor extends ClientSideBaseVisitor {
11
8
  constructor(schema, fragments, rawConfig) {
12
9
  super(schema, fragments, rawConfig, {
13
10
  rawRequest: getConfigValue(rawConfig.rawRequest, false),
@@ -18,10 +15,8 @@ class GraphQLRequestVisitor extends ClientSideBaseVisitor {
18
15
  const typeImport = this.config.useTypeImports ? 'import type' : 'import';
19
16
  this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);
20
17
  this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);
21
- if (this.config.rawRequest) {
22
- if (this.config.documentMode !== DocumentMode.string) {
23
- this._additionalImports.push(`import { print } from 'graphql'`);
24
- }
18
+ if (this.config.rawRequest && this.config.documentMode !== DocumentMode.string) {
19
+ this._additionalImports.push(`import { print } from 'graphql'`);
25
20
  }
26
21
  }
27
22
  OperationDefinition(node) {
@@ -87,33 +82,3 @@ ${allPossibleActions.join(',\n')}
87
82
  export type Sdk = ReturnType<typeof getSdk>;`;
88
83
  }
89
84
  }
90
-
91
- const plugin = (schema, documents, config) => {
92
- const allAst = concatAST(documents.map(v => v.document));
93
- const allFragments = [
94
- ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
95
- node: fragmentDef,
96
- name: fragmentDef.name.value,
97
- onType: fragmentDef.typeCondition.name.value,
98
- isExternal: false,
99
- })),
100
- ...(config.externalFragments || []),
101
- ];
102
- const visitor = new GraphQLRequestVisitor(schema, allFragments, config);
103
- const visitorResult = oldVisit(allAst, { leave: visitor });
104
- return {
105
- prepend: visitor.getImports(),
106
- content: [
107
- visitor.fragments,
108
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
109
- visitor.sdkContent,
110
- ].join('\n'),
111
- };
112
- };
113
- const validate = async (schema, documents, config, outputFile) => {
114
- if (extname(outputFile) !== '.ts') {
115
- throw new Error(`Plugin "typescript-graphql-request" requires extension to be ".ts"!`);
116
- }
117
- };
118
-
119
- export { GraphQLRequestVisitor, plugin, validate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-graphql-request",
3
- "version": "4.4.10-alpha-7a65ba05d.0",
3
+ "version": "4.4.12-alpha-5d16266dd.0",
4
4
  "description": "GraphQL Code Generator plugin for generating a ready-to-use SDK based on graphql-request and 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",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@graphql-codegen/plugin-helpers": "^2.4.0",
12
- "@graphql-codegen/visitor-plugin-common": "2.9.1-alpha-7a65ba05d.0",
12
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-5d16266dd.0",
13
13
  "auto-bind": "~4.0.0",
14
14
  "tslib": "~2.4.0"
15
15
  },
@@ -19,21 +19,28 @@
19
19
  "directory": "packages/plugins/typescript/graphql-request"
20
20
  },
21
21
  "license": "MIT",
22
- "main": "index.js",
23
- "module": "index.mjs",
24
- "typings": "index.d.ts",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "typings": "typings/index.d.ts",
25
25
  "typescript": {
26
- "definition": "index.d.ts"
26
+ "definition": "typings/index.d.ts"
27
27
  },
28
+ "type": "module",
28
29
  "exports": {
29
- "./package.json": "./package.json",
30
30
  ".": {
31
- "require": "./index.js",
32
- "import": "./index.mjs"
31
+ "require": {
32
+ "types": "./typings/index.d.ts",
33
+ "default": "./cjs/index.js"
34
+ },
35
+ "import": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ },
39
+ "default": {
40
+ "types": "./typings/index.d.ts",
41
+ "default": "./esm/index.js"
42
+ }
33
43
  },
34
- "./*": {
35
- "require": "./*.js",
36
- "import": "./*.mjs"
37
- }
44
+ "./package.json": "./package.json"
38
45
  }
39
- }
46
+ }
File without changes
@@ -1,6 +1,6 @@
1
1
  import { PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
2
- import { GraphQLRequestVisitor } from './visitor';
3
- import { RawGraphQLRequestPluginConfig } from './config';
2
+ import { GraphQLRequestVisitor } from './visitor.js';
3
+ import { RawGraphQLRequestPluginConfig } from './config.js';
4
4
  export declare const plugin: PluginFunction<RawGraphQLRequestPluginConfig>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { GraphQLRequestVisitor };
@@ -1,6 +1,6 @@
1
1
  import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
2
2
  import { GraphQLSchema, OperationDefinitionNode } from 'graphql';
3
- import { RawGraphQLRequestPluginConfig } from './config';
3
+ import { RawGraphQLRequestPluginConfig } from './config.js';
4
4
  export interface GraphQLRequestPluginConfig extends ClientSideBasePluginConfig {
5
5
  rawRequest: boolean;
6
6
  extensionsType: string;