@graphql-codegen/typescript-jit-sdk 2.0.12 → 2.1.0-alpha-29eb1293b.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,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JitSdkVisitor = exports.validate = exports.plugin = void 0;
4
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
5
+ const graphql_1 = require("graphql");
6
+ const path_1 = require("path");
7
+ const visitor_js_1 = require("./visitor.js");
8
+ Object.defineProperty(exports, "JitSdkVisitor", { enumerable: true, get: function () { return visitor_js_1.JitSdkVisitor; } });
9
+ const plugin = (schema, documents, config) => {
10
+ const allAst = (0, graphql_1.concatAST)(documents.reduce((prev, v) => {
11
+ return [...prev, v.document];
12
+ }, []));
13
+ const allFragments = [
14
+ ...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
15
+ node: fragmentDef,
16
+ name: fragmentDef.name.value,
17
+ onType: fragmentDef.typeCondition.name.value,
18
+ isExternal: false,
19
+ })),
20
+ ...(config.externalFragments || []),
21
+ ];
22
+ const visitor = new visitor_js_1.JitSdkVisitor(schema, allFragments, config);
23
+ const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
24
+ return {
25
+ prepend: visitor.getImports(),
26
+ content: [
27
+ visitor.fragments,
28
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
29
+ visitor.sdkContent,
30
+ ].join('\n'),
31
+ };
32
+ };
33
+ exports.plugin = plugin;
34
+ const validate = async (schema, documents, config, outputFile) => {
35
+ if ((0, path_1.extname)(outputFile) !== '.ts') {
36
+ throw new Error(`Plugin "typescript-jit-sdk" requires extension to be ".ts"!`);
37
+ }
38
+ };
39
+ exports.validate = validate;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,26 +1,21 @@
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 path = require('path');
10
- const visitorPluginCommon = require('@graphql-codegen/visitor-plugin-common');
11
- const autoBind = _interopDefault(require('auto-bind'));
12
-
13
- class JitSdkVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JitSdkVisitor = 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");
8
+ class JitSdkVisitor extends visitor_plugin_common_1.ClientSideBaseVisitor {
14
9
  constructor(schema, fragments, rawConfig) {
15
10
  super(schema, fragments, rawConfig, {});
16
11
  this._operationsToInclude = [];
17
- autoBind(this);
12
+ (0, auto_bind_1.default)(this);
18
13
  const importType = this.config.useTypeImports ? 'import type' : 'import';
19
14
  this._additionalImports.push(`${importType} { GraphQLSchema, ExecutionResult } from 'graphql';`);
20
- if (this.config.documentMode !== visitorPluginCommon.DocumentMode.string && this.config.documentMode !== visitorPluginCommon.DocumentMode.graphQLTag) {
15
+ if (this.config.documentMode !== visitor_plugin_common_1.DocumentMode.string && this.config.documentMode !== visitor_plugin_common_1.DocumentMode.graphQLTag) {
21
16
  this._additionalImports.push(`${importType} { DocumentNode } from 'graphql';`);
22
17
  }
23
- if (this.config.documentMode === visitorPluginCommon.DocumentMode.string) {
18
+ if (this.config.documentMode === visitor_plugin_common_1.DocumentMode.string) {
24
19
  this._additionalImports.push(`import { parse } from 'graphql';`);
25
20
  }
26
21
  this._additionalImports.push(`import { compileQuery, isCompiledQuery, CompilerOptions } from 'graphql-jit';`);
@@ -28,7 +23,7 @@ class JitSdkVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
28
23
  }
29
24
  buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
30
25
  if (node.name == null) {
31
- throw new Error("Plugin 'Jit-sdk' cannot generate SDK for unnamed operation.\n\n" + graphql.print(node));
26
+ throw new Error("Plugin 'Jit-sdk' cannot generate SDK for unnamed operation.\n\n" + (0, graphql_1.print)(node));
32
27
  }
33
28
  else {
34
29
  this._operationsToInclude.push({
@@ -48,7 +43,7 @@ class JitSdkVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
48
43
  for (const o of this._operationsToInclude) {
49
44
  const operationName = o.node.name.value;
50
45
  const compiledQueryVariableName = `${operationName}Compiled`;
51
- compiledQueries.push(visitorPluginCommon.indentMultiline(`const ${compiledQueryVariableName} = compileQuery(schema, ${this.config.documentMode === visitorPluginCommon.DocumentMode.string
46
+ compiledQueries.push((0, visitor_plugin_common_1.indentMultiline)(`const ${compiledQueryVariableName} = compileQuery(schema, ${this.config.documentMode === visitor_plugin_common_1.DocumentMode.string
52
47
  ? `parse(${o.documentVariableName})`
53
48
  : o.documentVariableName}, '${operationName}', jitOptions);
54
49
  if(!(isCompiledQuery(${compiledQueryVariableName}))) {
@@ -57,7 +52,7 @@ if(!(isCompiledQuery(${compiledQueryVariableName}))) {
57
52
  }`, 2));
58
53
  const optionalVariables = !o.node.variableDefinitions ||
59
54
  o.node.variableDefinitions.length === 0 ||
60
- o.node.variableDefinitions.every(v => v.type.kind !== graphql.Kind.NON_NULL_TYPE || v.defaultValue);
55
+ o.node.variableDefinitions.every(v => v.type.kind !== graphql_1.Kind.NON_NULL_TYPE || v.defaultValue);
61
56
  const methodName = o.operationType === 'Subscription' ? 'subscribe!' : 'query';
62
57
  const handlerName = o.operationType === 'Subscription' ? 'handleSubscriptionResult' : 'handleExecutionResult';
63
58
  const returnType = o.operationType === 'Subscription'
@@ -66,7 +61,7 @@ if(!(isCompiledQuery(${compiledQueryVariableName}))) {
66
61
  if (o.operationType === 'Subscription') {
67
62
  hasSubscription = true;
68
63
  }
69
- sdkMethods.push(visitorPluginCommon.indentMultiline(`async ${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, context?: TOperationContext, root?: TOperationRoot): Promise<${returnType}> {
64
+ sdkMethods.push((0, visitor_plugin_common_1.indentMultiline)(`async ${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, context?: TOperationContext, root?: TOperationRoot): Promise<${returnType}> {
70
65
  const result = await ${compiledQueryVariableName}.${methodName}({
71
66
  ...globalRoot,
72
67
  ...root
@@ -108,37 +103,4 @@ ${sdkMethods.join(',\n')}
108
103
  export type Sdk = ReturnType<typeof getSdk>;`;
109
104
  }
110
105
  }
111
-
112
- const plugin = (schema, documents, config) => {
113
- const allAst = graphql.concatAST(documents.reduce((prev, v) => {
114
- return [...prev, v.document];
115
- }, []));
116
- const allFragments = [
117
- ...allAst.definitions.filter(d => d.kind === graphql.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
118
- node: fragmentDef,
119
- name: fragmentDef.name.value,
120
- onType: fragmentDef.typeCondition.name.value,
121
- isExternal: false,
122
- })),
123
- ...(config.externalFragments || []),
124
- ];
125
- const visitor = new JitSdkVisitor(schema, allFragments, config);
126
- const visitorResult = pluginHelpers.oldVisit(allAst, { leave: visitor });
127
- return {
128
- prepend: visitor.getImports(),
129
- content: [
130
- visitor.fragments,
131
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
132
- visitor.sdkContent,
133
- ].join('\n'),
134
- };
135
- };
136
- const validate = async (schema, documents, config, outputFile) => {
137
- if (path.extname(outputFile) !== '.ts') {
138
- throw new Error(`Plugin "typescript-jit-sdk" requires extension to be ".ts"!`);
139
- }
140
- };
141
-
142
106
  exports.JitSdkVisitor = JitSdkVisitor;
143
- exports.plugin = plugin;
144
- exports.validate = validate;
package/esm/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,34 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind } from 'graphql';
3
+ import { extname } from 'path';
4
+ import { JitSdkVisitor } from './visitor.js';
5
+ export const plugin = (schema, documents, config) => {
6
+ const allAst = concatAST(documents.reduce((prev, v) => {
7
+ return [...prev, v.document];
8
+ }, []));
9
+ const allFragments = [
10
+ ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
11
+ node: fragmentDef,
12
+ name: fragmentDef.name.value,
13
+ onType: fragmentDef.typeCondition.name.value,
14
+ isExternal: false,
15
+ })),
16
+ ...(config.externalFragments || []),
17
+ ];
18
+ const visitor = new JitSdkVisitor(schema, allFragments, config);
19
+ const visitorResult = oldVisit(allAst, { leave: visitor });
20
+ return {
21
+ prepend: visitor.getImports(),
22
+ content: [
23
+ visitor.fragments,
24
+ ...visitorResult.definitions.filter(t => typeof t === 'string'),
25
+ visitor.sdkContent,
26
+ ].join('\n'),
27
+ };
28
+ };
29
+ export const validate = async (schema, documents, config, outputFile) => {
30
+ if (extname(outputFile) !== '.ts') {
31
+ throw new Error(`Plugin "typescript-jit-sdk" requires extension to be ".ts"!`);
32
+ }
33
+ };
34
+ export { JitSdkVisitor };
@@ -1,10 +1,7 @@
1
- import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
- import { print, Kind, concatAST } from 'graphql';
3
- import { extname } from 'path';
4
- import { ClientSideBaseVisitor, DocumentMode, indentMultiline } from '@graphql-codegen/visitor-plugin-common';
1
+ import { ClientSideBaseVisitor, DocumentMode, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';
5
2
  import autoBind from 'auto-bind';
6
-
7
- class JitSdkVisitor extends ClientSideBaseVisitor {
3
+ import { Kind, print } from 'graphql';
4
+ export class JitSdkVisitor extends ClientSideBaseVisitor {
8
5
  constructor(schema, fragments, rawConfig) {
9
6
  super(schema, fragments, rawConfig, {});
10
7
  this._operationsToInclude = [];
@@ -102,35 +99,3 @@ ${sdkMethods.join(',\n')}
102
99
  export type Sdk = ReturnType<typeof getSdk>;`;
103
100
  }
104
101
  }
105
-
106
- const plugin = (schema, documents, config) => {
107
- const allAst = concatAST(documents.reduce((prev, v) => {
108
- return [...prev, v.document];
109
- }, []));
110
- const allFragments = [
111
- ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
112
- node: fragmentDef,
113
- name: fragmentDef.name.value,
114
- onType: fragmentDef.typeCondition.name.value,
115
- isExternal: false,
116
- })),
117
- ...(config.externalFragments || []),
118
- ];
119
- const visitor = new JitSdkVisitor(schema, allFragments, config);
120
- const visitorResult = oldVisit(allAst, { leave: visitor });
121
- return {
122
- prepend: visitor.getImports(),
123
- content: [
124
- visitor.fragments,
125
- ...visitorResult.definitions.filter(t => typeof t === 'string'),
126
- visitor.sdkContent,
127
- ].join('\n'),
128
- };
129
- };
130
- const validate = async (schema, documents, config, outputFile) => {
131
- if (extname(outputFile) !== '.ts') {
132
- throw new Error(`Plugin "typescript-jit-sdk" requires extension to be ".ts"!`);
133
- }
134
- };
135
-
136
- export { JitSdkVisitor, plugin, validate };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-jit-sdk",
3
- "version": "2.0.12",
3
+ "version": "2.1.0-alpha-29eb1293b.0",
4
4
  "description": "GraphQL Code Generator plugin for generating a ready-to-use SDK that uses GraphQL JIT",
5
5
  "peerDependencies": {
6
- "@graphql-tools/utils": "^8.2.4",
7
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
+ "graphql-tag": "^2.0.0",
8
8
  "graphql-jit": "^0.6.0 || ^0.7.0",
9
- "graphql-tag": "^2.0.0"
9
+ "@graphql-tools/utils": "^8.8.0"
10
10
  },
11
11
  "dependencies": {
12
- "@graphql-codegen/plugin-helpers": "^2.4.0",
13
- "@graphql-codegen/visitor-plugin-common": "2.10.0",
12
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-29eb1293b.0",
13
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-29eb1293b.0",
14
14
  "auto-bind": "~4.0.0",
15
15
  "tslib": "~2.4.0"
16
16
  },
@@ -20,21 +20,28 @@
20
20
  "directory": "packages/plugins/typescript/jit-sdk"
21
21
  },
22
22
  "license": "MIT",
23
- "main": "index.js",
24
- "module": "index.mjs",
25
- "typings": "index.d.ts",
23
+ "main": "cjs/index.js",
24
+ "module": "esm/index.js",
25
+ "typings": "typings/index.d.ts",
26
26
  "typescript": {
27
- "definition": "index.d.ts"
27
+ "definition": "typings/index.d.ts"
28
28
  },
29
+ "type": "module",
29
30
  "exports": {
30
- "./package.json": "./package.json",
31
31
  ".": {
32
- "require": "./index.js",
33
- "import": "./index.mjs"
32
+ "require": {
33
+ "types": "./typings/index.d.ts",
34
+ "default": "./cjs/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./typings/index.d.ts",
38
+ "default": "./esm/index.js"
39
+ },
40
+ "default": {
41
+ "types": "./typings/index.d.ts",
42
+ "default": "./esm/index.js"
43
+ }
34
44
  },
35
- "./*": {
36
- "require": "./*.js",
37
- "import": "./*.mjs"
38
- }
45
+ "./package.json": "./package.json"
39
46
  }
40
- }
47
+ }
File without changes
@@ -1,6 +1,6 @@
1
1
  import { PluginFunction, PluginValidateFn } from '@graphql-codegen/plugin-helpers';
2
- import { RawJitSdkPluginConfig } from './config';
3
- import { JitSdkVisitor } from './visitor';
2
+ import { RawJitSdkPluginConfig } from './config.js';
3
+ import { JitSdkVisitor } from './visitor.js';
4
4
  export declare const plugin: PluginFunction<RawJitSdkPluginConfig>;
5
5
  export declare const validate: PluginValidateFn<any>;
6
6
  export { JitSdkVisitor };
@@ -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 { RawJitSdkPluginConfig } from './config';
3
+ import { RawJitSdkPluginConfig } from './config.js';
4
4
  export interface JitSdkPluginConfig extends ClientSideBasePluginConfig {
5
5
  }
6
6
  export declare class JitSdkVisitor extends ClientSideBaseVisitor<RawJitSdkPluginConfig, JitSdkPluginConfig> {