@graphql-codegen/typescript-jit-sdk 1.2.2-alpha-6cdbcf02e.0 → 2.0.1-alpha-bc33c031d.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/index.js +8 -3
- package/index.mjs +8 -3
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -23,7 +23,7 @@ class JitSdkVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
23
23
|
if (this.config.documentMode === visitorPluginCommon.DocumentMode.string) {
|
|
24
24
|
this._additionalImports.push(`import { parse } from 'graphql';`);
|
|
25
25
|
}
|
|
26
|
-
this._additionalImports.push(`import { compileQuery, isCompiledQuery } from 'graphql-jit';`);
|
|
26
|
+
this._additionalImports.push(`import { compileQuery, isCompiledQuery, CompilerOptions } from 'graphql-jit';`);
|
|
27
27
|
this._additionalImports.push(`import { AggregateError, isAsyncIterable, mapAsyncIterator } from '@graphql-tools/utils';`);
|
|
28
28
|
}
|
|
29
29
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
@@ -50,7 +50,7 @@ class JitSdkVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
|
|
|
50
50
|
const compiledQueryVariableName = `${operationName}Compiled`;
|
|
51
51
|
compiledQueries.push(visitorPluginCommon.indentMultiline(`const ${compiledQueryVariableName} = compileQuery(schema, ${this.config.documentMode === visitorPluginCommon.DocumentMode.string
|
|
52
52
|
? `parse(${o.documentVariableName})`
|
|
53
|
-
: o.documentVariableName}, '${operationName}');
|
|
53
|
+
: o.documentVariableName}, '${operationName}', jitOptions);
|
|
54
54
|
if(!(isCompiledQuery(${compiledQueryVariableName}))) {
|
|
55
55
|
const originalErrors = ${compiledQueryVariableName}?.errors?.map(error => error.originalError || error) || [];
|
|
56
56
|
throw new AggregateError(originalErrors, \`Failed to compile ${operationName}: \\n\\t\${originalErrors.join('\\n\\t')}\`);
|
|
@@ -93,7 +93,12 @@ if(!(isCompiledQuery(${compiledQueryVariableName}))) {
|
|
|
93
93
|
}
|
|
94
94
|
return result.data as unknown as T;
|
|
95
95
|
}
|
|
96
|
-
export
|
|
96
|
+
export interface SdkOptions<TGlobalContext = any, TGlobalRoot = any> {
|
|
97
|
+
globalContext?: TGlobalContext;
|
|
98
|
+
globalRoot?: TGlobalRoot;
|
|
99
|
+
jitOptions?: Partial<CompilerOptions>;
|
|
100
|
+
}
|
|
101
|
+
export function getSdk<TGlobalContext = any, TGlobalRoot = any, TOperationContext = any, TOperationRoot = any>(schema: GraphQLSchema, { globalContext, globalRoot, jitOptions = {} }: SdkOptions<TGlobalContext, TGlobalRoot> = {}) {
|
|
97
102
|
${compiledQueries.join('\n\n')}
|
|
98
103
|
|
|
99
104
|
return {
|
package/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ class JitSdkVisitor extends ClientSideBaseVisitor {
|
|
|
17
17
|
if (this.config.documentMode === DocumentMode.string) {
|
|
18
18
|
this._additionalImports.push(`import { parse } from 'graphql';`);
|
|
19
19
|
}
|
|
20
|
-
this._additionalImports.push(`import { compileQuery, isCompiledQuery } from 'graphql-jit';`);
|
|
20
|
+
this._additionalImports.push(`import { compileQuery, isCompiledQuery, CompilerOptions } from 'graphql-jit';`);
|
|
21
21
|
this._additionalImports.push(`import { AggregateError, isAsyncIterable, mapAsyncIterator } from '@graphql-tools/utils';`);
|
|
22
22
|
}
|
|
23
23
|
buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {
|
|
@@ -44,7 +44,7 @@ class JitSdkVisitor extends ClientSideBaseVisitor {
|
|
|
44
44
|
const compiledQueryVariableName = `${operationName}Compiled`;
|
|
45
45
|
compiledQueries.push(indentMultiline(`const ${compiledQueryVariableName} = compileQuery(schema, ${this.config.documentMode === DocumentMode.string
|
|
46
46
|
? `parse(${o.documentVariableName})`
|
|
47
|
-
: o.documentVariableName}, '${operationName}');
|
|
47
|
+
: o.documentVariableName}, '${operationName}', jitOptions);
|
|
48
48
|
if(!(isCompiledQuery(${compiledQueryVariableName}))) {
|
|
49
49
|
const originalErrors = ${compiledQueryVariableName}?.errors?.map(error => error.originalError || error) || [];
|
|
50
50
|
throw new AggregateError(originalErrors, \`Failed to compile ${operationName}: \\n\\t\${originalErrors.join('\\n\\t')}\`);
|
|
@@ -87,7 +87,12 @@ if(!(isCompiledQuery(${compiledQueryVariableName}))) {
|
|
|
87
87
|
}
|
|
88
88
|
return result.data as unknown as T;
|
|
89
89
|
}
|
|
90
|
-
export
|
|
90
|
+
export interface SdkOptions<TGlobalContext = any, TGlobalRoot = any> {
|
|
91
|
+
globalContext?: TGlobalContext;
|
|
92
|
+
globalRoot?: TGlobalRoot;
|
|
93
|
+
jitOptions?: Partial<CompilerOptions>;
|
|
94
|
+
}
|
|
95
|
+
export function getSdk<TGlobalContext = any, TGlobalRoot = any, TOperationContext = any, TOperationRoot = any>(schema: GraphQLSchema, { globalContext, globalRoot, jitOptions = {} }: SdkOptions<TGlobalContext, TGlobalRoot> = {}) {
|
|
91
96
|
${compiledQueries.join('\n\n')}
|
|
92
97
|
|
|
93
98
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-jit-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1-alpha-bc33c031d.0",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating a ready-to-use SDK that uses GraphQL JIT",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@graphql-tools/utils": "^8.2.4",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"graphql-tag": "^2.0.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@graphql-codegen/plugin-helpers": "2.3.3-alpha-
|
|
13
|
-
"@graphql-codegen/visitor-plugin-common": "2.5.3-alpha-
|
|
12
|
+
"@graphql-codegen/plugin-helpers": "2.3.3-alpha-bc33c031d.0",
|
|
13
|
+
"@graphql-codegen/visitor-plugin-common": "2.5.3-alpha-bc33c031d.0",
|
|
14
14
|
"auto-bind": "~4.0.0",
|
|
15
15
|
"tslib": "~2.3.0"
|
|
16
16
|
},
|