@graphql-mesh/runtime 0.96.5-alpha-20230914192235-1ddf4c590 → 0.96.5
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/get-mesh.js +21 -4
- package/cjs/in-context-sdk.js +0 -1
- package/cjs/useSubschema.js +62 -20
- package/cjs/utils.js +17 -1
- package/esm/get-mesh.js +24 -7
- package/esm/in-context-sdk.js +0 -1
- package/esm/useSubschema.js +63 -21
- package/esm/utils.js +17 -1
- package/package.json +6 -4
- package/typings/utils.d.cts +2 -0
- package/typings/utils.d.ts +2 -0
package/cjs/get-mesh.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.getMesh = exports.wrapFetchWithPlugins = void 0;
|
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const core_1 = require("@envelop/core");
|
|
6
6
|
const extended_validation_1 = require("@envelop/extended-validation");
|
|
7
|
+
const graphql_jit_1 = require("@envelop/graphql-jit");
|
|
7
8
|
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
8
9
|
const utils_1 = require("@graphql-mesh/utils");
|
|
9
10
|
const delegate_1 = require("@graphql-tools/delegate");
|
|
@@ -188,14 +189,30 @@ async function getMesh(options) {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
let inContextSDK;
|
|
191
|
-
|
|
192
|
+
let subschema;
|
|
193
|
+
if (unifiedSubschema.executor != null || unifiedSubschema.transforms?.length) {
|
|
194
|
+
subschema = new delegate_1.Subschema(unifiedSubschema);
|
|
195
|
+
}
|
|
192
196
|
const plugins = [
|
|
193
197
|
(0, core_1.useEngine)({
|
|
198
|
+
execute: graphql_1.execute,
|
|
194
199
|
validate: graphql_1.validate,
|
|
195
200
|
parse: utils_1.parseWithCache,
|
|
196
201
|
specifiedRules: graphql_1.specifiedRules,
|
|
197
202
|
}),
|
|
198
|
-
(
|
|
203
|
+
...(subschema
|
|
204
|
+
? [(0, useSubschema_js_1.useSubschema)(new delegate_1.Subschema(unifiedSubschema))]
|
|
205
|
+
: [
|
|
206
|
+
(0, core_1.useSchema)(unifiedSubschema.schema),
|
|
207
|
+
(0, graphql_jit_1.useGraphQlJit)({
|
|
208
|
+
customJSONSerializer: !unifiedSubschema.schema.getType('BigInt'),
|
|
209
|
+
disableLeafSerialization: true,
|
|
210
|
+
}, {
|
|
211
|
+
enableIf(args) {
|
|
212
|
+
return !(0, utils_js_1.isStreamOperation)(args.document);
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
]),
|
|
199
216
|
(0, core_1.useExtendContext)(() => {
|
|
200
217
|
if (!inContextSDK) {
|
|
201
218
|
const onDelegateHooks = [];
|
|
@@ -204,7 +221,7 @@ async function getMesh(options) {
|
|
|
204
221
|
onDelegateHooks.push(plugin.onDelegate);
|
|
205
222
|
}
|
|
206
223
|
}
|
|
207
|
-
inContextSDK = (0, in_context_sdk_js_1.getInContextSDK)(subschema.transformedSchema, rawSources, logger, onDelegateHooks);
|
|
224
|
+
inContextSDK = (0, in_context_sdk_js_1.getInContextSDK)(subschema ? subschema.transformedSchema : unifiedSubschema.schema, rawSources, logger, onDelegateHooks);
|
|
208
225
|
}
|
|
209
226
|
return inContextSDK;
|
|
210
227
|
}),
|
|
@@ -258,7 +275,7 @@ async function getMesh(options) {
|
|
|
258
275
|
}
|
|
259
276
|
return {
|
|
260
277
|
get schema() {
|
|
261
|
-
return subschema.transformedSchema;
|
|
278
|
+
return subschema ? subschema.transformedSchema : unifiedSubschema.schema;
|
|
262
279
|
},
|
|
263
280
|
rawSources,
|
|
264
281
|
cache,
|
package/cjs/in-context-sdk.js
CHANGED
|
@@ -108,7 +108,6 @@ function getInContextSDK(unifiedSchema, rawSources, logger, onDelegateHooks) {
|
|
|
108
108
|
field: fieldName,
|
|
109
109
|
});
|
|
110
110
|
selectionSet = (0, graphql_1.print)(operationNode.selectionSet.selections[0].selectionSet);
|
|
111
|
-
console.log({ selectionSet });
|
|
112
111
|
}
|
|
113
112
|
else {
|
|
114
113
|
throw new Error(`You have to provide 'selectionSet' for context.${rawSource.name}.${rootType.name}.${fieldName}`);
|
package/cjs/useSubschema.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSubschema = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
+
const graphql_jit_1 = require("graphql-jit");
|
|
5
6
|
const core_1 = require("@envelop/core");
|
|
6
7
|
const utils_1 = require("@graphql-mesh/utils");
|
|
7
8
|
const delegate_1 = require("@graphql-tools/delegate");
|
|
@@ -10,24 +11,34 @@ var IntrospectionQueryType;
|
|
|
10
11
|
(function (IntrospectionQueryType) {
|
|
11
12
|
IntrospectionQueryType["FEDERATION"] = "FEDERATION";
|
|
12
13
|
IntrospectionQueryType["REGULAR"] = "REGULAR";
|
|
14
|
+
IntrospectionQueryType["STREAM"] = "STREAM";
|
|
13
15
|
})(IntrospectionQueryType || (IntrospectionQueryType = {}));
|
|
14
|
-
function getIntrospectionOperationType(operationAST) {
|
|
16
|
+
const getIntrospectionOperationType = (0, utils_2.memoize1)(function getIntrospectionOperationType(operationAST) {
|
|
15
17
|
let introspectionQueryType = null;
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
if (operationAST.operation === 'query' && operationAST.selectionSet.selections.length === 1) {
|
|
19
|
+
(0, graphql_1.visit)(operationAST, {
|
|
20
|
+
Field: (node) => {
|
|
21
|
+
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
22
|
+
introspectionQueryType = IntrospectionQueryType.REGULAR;
|
|
23
|
+
return graphql_1.BREAK;
|
|
24
|
+
}
|
|
25
|
+
if (node.name.value === '_service') {
|
|
26
|
+
introspectionQueryType = IntrospectionQueryType.FEDERATION;
|
|
27
|
+
return graphql_1.BREAK;
|
|
28
|
+
}
|
|
29
|
+
if (node.directives?.some(d => d.name.value === 'stream')) {
|
|
30
|
+
introspectionQueryType = IntrospectionQueryType.STREAM;
|
|
31
|
+
return graphql_1.BREAK;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
28
36
|
return introspectionQueryType;
|
|
29
|
-
}
|
|
37
|
+
});
|
|
30
38
|
function getExecuteFn(subschema) {
|
|
39
|
+
const compiledQueryCache = new WeakMap();
|
|
40
|
+
const transformedRequestCache = new WeakMap();
|
|
41
|
+
const hasBigInt = subschema.schema.getType('BigInt') != null;
|
|
31
42
|
return function subschemaExecute(args) {
|
|
32
43
|
const originalRequest = {
|
|
33
44
|
document: args.document,
|
|
@@ -52,6 +63,7 @@ function getExecuteFn(subschema) {
|
|
|
52
63
|
else if (introspectionQueryType === IntrospectionQueryType.REGULAR) {
|
|
53
64
|
return (0, graphql_1.execute)(args);
|
|
54
65
|
}
|
|
66
|
+
const isStream = introspectionQueryType === IntrospectionQueryType.STREAM;
|
|
55
67
|
const delegationContext = {
|
|
56
68
|
subschema,
|
|
57
69
|
subschemaConfig: subschema,
|
|
@@ -67,23 +79,53 @@ function getExecuteFn(subschema) {
|
|
|
67
79
|
};
|
|
68
80
|
let executor = subschema.executor;
|
|
69
81
|
if (executor == null) {
|
|
70
|
-
|
|
82
|
+
if (isStream) {
|
|
83
|
+
executor = (0, delegate_1.createDefaultExecutor)(subschema.schema);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
executor = function subschemaExecutor(request) {
|
|
87
|
+
let compiledQuery = compiledQueryCache.get(request.document);
|
|
88
|
+
if (!compiledQuery) {
|
|
89
|
+
const compilationResult = (0, graphql_jit_1.compileQuery)(subschema.schema, request.document, request.operationName, {
|
|
90
|
+
customJSONSerializer: !hasBigInt,
|
|
91
|
+
disableLeafSerialization: true,
|
|
92
|
+
});
|
|
93
|
+
if (!(0, graphql_jit_1.isCompiledQuery)(compilationResult)) {
|
|
94
|
+
return compilationResult;
|
|
95
|
+
}
|
|
96
|
+
compiledQuery = compilationResult;
|
|
97
|
+
compiledQueryCache.set(request.document, compiledQuery);
|
|
98
|
+
}
|
|
99
|
+
if (operationAST.operation === 'subscription') {
|
|
100
|
+
return compiledQuery.subscribe(request.rootValue, request.context, request.variables);
|
|
101
|
+
}
|
|
102
|
+
return compiledQuery.query(request.rootValue, request.context, request.variables);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
71
105
|
}
|
|
72
106
|
/*
|
|
73
107
|
if (subschema.batch) {
|
|
74
108
|
executor = createBatchingExecutor(executor);
|
|
75
109
|
}
|
|
76
110
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
111
|
+
let transformedRequestAndContext = transformedRequestCache.get(originalRequest.document);
|
|
112
|
+
if (!transformedRequestAndContext) {
|
|
113
|
+
const transformationContext = {};
|
|
114
|
+
const transformedRequest = (0, utils_1.applyRequestTransforms)(originalRequest, delegationContext, transformationContext, subschema.transforms);
|
|
115
|
+
transformedRequestAndContext = {
|
|
116
|
+
transformedRequest,
|
|
117
|
+
transformationContext,
|
|
118
|
+
};
|
|
119
|
+
transformedRequestCache.set(originalRequest.document, transformedRequestAndContext);
|
|
120
|
+
}
|
|
79
121
|
function handleResult(originalResult) {
|
|
80
122
|
if ((0, utils_2.isAsyncIterable)(originalResult)) {
|
|
81
|
-
return (0, core_1.mapAsyncIterator)(originalResult, singleResult => (0, utils_1.applyResultTransforms)(singleResult, delegationContext, transformationContext, subschema.transforms));
|
|
123
|
+
return (0, core_1.mapAsyncIterator)(originalResult, singleResult => (0, utils_1.applyResultTransforms)(singleResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms));
|
|
82
124
|
}
|
|
83
|
-
const transformedResult = (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformationContext, subschema.transforms);
|
|
125
|
+
const transformedResult = (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms);
|
|
84
126
|
return transformedResult;
|
|
85
127
|
}
|
|
86
|
-
const originalResult$ = executor(transformedRequest);
|
|
128
|
+
const originalResult$ = executor(transformedRequestAndContext.transformedRequest);
|
|
87
129
|
if ((0, utils_2.isPromise)(originalResult$)) {
|
|
88
130
|
return originalResult$.then(handleResult);
|
|
89
131
|
}
|
package/cjs/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.iterateAsync = void 0;
|
|
3
|
+
exports.isStreamOperation = exports.iterateAsync = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
4
5
|
const utils_1 = require("@graphql-tools/utils");
|
|
5
6
|
function iterateAsync(iterable, callback, results) {
|
|
6
7
|
const iterator = iterable[Symbol.iterator]();
|
|
@@ -26,3 +27,18 @@ function iterateAsync(iterable, callback, results) {
|
|
|
26
27
|
return iterate();
|
|
27
28
|
}
|
|
28
29
|
exports.iterateAsync = iterateAsync;
|
|
30
|
+
exports.isStreamOperation = (0, utils_1.memoize1)(function isStreamOperation(astNode) {
|
|
31
|
+
let isStream = false;
|
|
32
|
+
(0, graphql_1.visit)(astNode, {
|
|
33
|
+
Field: {
|
|
34
|
+
enter(node) {
|
|
35
|
+
if (node.directives?.some(d => d.name.value === 'stream')) {
|
|
36
|
+
isStream = true;
|
|
37
|
+
return graphql_1.BREAK;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return isStream;
|
|
44
|
+
});
|
package/esm/get-mesh.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getOperationAST, specifiedRules, validate, } from 'graphql';
|
|
2
|
-
import { envelop, useEngine, useExtendContext } from '@envelop/core';
|
|
1
|
+
import { execute, getOperationAST, specifiedRules, validate, } from 'graphql';
|
|
2
|
+
import { envelop, useEngine, useExtendContext, useSchema } from '@envelop/core';
|
|
3
3
|
import { OneOfInputObjectsRule, useExtendedValidation } from '@envelop/extended-validation';
|
|
4
|
+
import { useGraphQlJit } from '@envelop/graphql-jit';
|
|
4
5
|
import { process } from '@graphql-mesh/cross-helpers';
|
|
5
6
|
import { applySchemaTransforms, DefaultLogger, getHeadersObj, groupTransforms, parseWithCache, PubSub, } from '@graphql-mesh/utils';
|
|
6
7
|
import { Subschema } from '@graphql-tools/delegate';
|
|
@@ -9,7 +10,7 @@ import { fetch as defaultFetchFn } from '@whatwg-node/fetch';
|
|
|
9
10
|
import { MESH_CONTEXT_SYMBOL } from './constants.js';
|
|
10
11
|
import { getInContextSDK } from './in-context-sdk.js';
|
|
11
12
|
import { useSubschema } from './useSubschema.js';
|
|
12
|
-
import { iterateAsync } from './utils.js';
|
|
13
|
+
import { isStreamOperation, iterateAsync } from './utils.js';
|
|
13
14
|
const memoizedGetEnvelopedFactory = memoize1(function getEnvelopedFactory(plugins) {
|
|
14
15
|
return envelop({
|
|
15
16
|
plugins,
|
|
@@ -184,14 +185,30 @@ export async function getMesh(options) {
|
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
let inContextSDK;
|
|
187
|
-
|
|
188
|
+
let subschema;
|
|
189
|
+
if (unifiedSubschema.executor != null || unifiedSubschema.transforms?.length) {
|
|
190
|
+
subschema = new Subschema(unifiedSubschema);
|
|
191
|
+
}
|
|
188
192
|
const plugins = [
|
|
189
193
|
useEngine({
|
|
194
|
+
execute,
|
|
190
195
|
validate,
|
|
191
196
|
parse: parseWithCache,
|
|
192
197
|
specifiedRules,
|
|
193
198
|
}),
|
|
194
|
-
|
|
199
|
+
...(subschema
|
|
200
|
+
? [useSubschema(new Subschema(unifiedSubschema))]
|
|
201
|
+
: [
|
|
202
|
+
useSchema(unifiedSubschema.schema),
|
|
203
|
+
useGraphQlJit({
|
|
204
|
+
customJSONSerializer: !unifiedSubschema.schema.getType('BigInt'),
|
|
205
|
+
disableLeafSerialization: true,
|
|
206
|
+
}, {
|
|
207
|
+
enableIf(args) {
|
|
208
|
+
return !isStreamOperation(args.document);
|
|
209
|
+
},
|
|
210
|
+
}),
|
|
211
|
+
]),
|
|
195
212
|
useExtendContext(() => {
|
|
196
213
|
if (!inContextSDK) {
|
|
197
214
|
const onDelegateHooks = [];
|
|
@@ -200,7 +217,7 @@ export async function getMesh(options) {
|
|
|
200
217
|
onDelegateHooks.push(plugin.onDelegate);
|
|
201
218
|
}
|
|
202
219
|
}
|
|
203
|
-
inContextSDK = getInContextSDK(subschema.transformedSchema, rawSources, logger, onDelegateHooks);
|
|
220
|
+
inContextSDK = getInContextSDK(subschema ? subschema.transformedSchema : unifiedSubschema.schema, rawSources, logger, onDelegateHooks);
|
|
204
221
|
}
|
|
205
222
|
return inContextSDK;
|
|
206
223
|
}),
|
|
@@ -254,7 +271,7 @@ export async function getMesh(options) {
|
|
|
254
271
|
}
|
|
255
272
|
return {
|
|
256
273
|
get schema() {
|
|
257
|
-
return subschema.transformedSchema;
|
|
274
|
+
return subschema ? subschema.transformedSchema : unifiedSubschema.schema;
|
|
258
275
|
},
|
|
259
276
|
rawSources,
|
|
260
277
|
cache,
|
package/esm/in-context-sdk.js
CHANGED
|
@@ -105,7 +105,6 @@ export function getInContextSDK(unifiedSchema, rawSources, logger, onDelegateHoo
|
|
|
105
105
|
field: fieldName,
|
|
106
106
|
});
|
|
107
107
|
selectionSet = print(operationNode.selectionSet.selections[0].selectionSet);
|
|
108
|
-
console.log({ selectionSet });
|
|
109
108
|
}
|
|
110
109
|
else {
|
|
111
110
|
throw new Error(`You have to provide 'selectionSet' for context.${rawSource.name}.${rootType.name}.${fieldName}`);
|
package/esm/useSubschema.js
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
import { BREAK, execute, visit } from 'graphql';
|
|
2
|
+
import { compileQuery, isCompiledQuery } from 'graphql-jit';
|
|
2
3
|
import { mapAsyncIterator } from '@envelop/core';
|
|
3
4
|
import { applyRequestTransforms, applyResultTransforms } from '@graphql-mesh/utils';
|
|
4
5
|
import { applySchemaTransforms, createDefaultExecutor, } from '@graphql-tools/delegate';
|
|
5
|
-
import { getDefinedRootType, getOperationASTFromRequest, isAsyncIterable, isPromise, printSchemaWithDirectives, } from '@graphql-tools/utils';
|
|
6
|
+
import { getDefinedRootType, getOperationASTFromRequest, isAsyncIterable, isPromise, memoize1, printSchemaWithDirectives, } from '@graphql-tools/utils';
|
|
6
7
|
var IntrospectionQueryType;
|
|
7
8
|
(function (IntrospectionQueryType) {
|
|
8
9
|
IntrospectionQueryType["FEDERATION"] = "FEDERATION";
|
|
9
10
|
IntrospectionQueryType["REGULAR"] = "REGULAR";
|
|
11
|
+
IntrospectionQueryType["STREAM"] = "STREAM";
|
|
10
12
|
})(IntrospectionQueryType || (IntrospectionQueryType = {}));
|
|
11
|
-
function getIntrospectionOperationType(operationAST) {
|
|
13
|
+
const getIntrospectionOperationType = memoize1(function getIntrospectionOperationType(operationAST) {
|
|
12
14
|
let introspectionQueryType = null;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
if (operationAST.operation === 'query' && operationAST.selectionSet.selections.length === 1) {
|
|
16
|
+
visit(operationAST, {
|
|
17
|
+
Field: (node) => {
|
|
18
|
+
if (node.name.value === '__schema' || node.name.value === '__type') {
|
|
19
|
+
introspectionQueryType = IntrospectionQueryType.REGULAR;
|
|
20
|
+
return BREAK;
|
|
21
|
+
}
|
|
22
|
+
if (node.name.value === '_service') {
|
|
23
|
+
introspectionQueryType = IntrospectionQueryType.FEDERATION;
|
|
24
|
+
return BREAK;
|
|
25
|
+
}
|
|
26
|
+
if (node.directives?.some(d => d.name.value === 'stream')) {
|
|
27
|
+
introspectionQueryType = IntrospectionQueryType.STREAM;
|
|
28
|
+
return BREAK;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
25
33
|
return introspectionQueryType;
|
|
26
|
-
}
|
|
34
|
+
});
|
|
27
35
|
function getExecuteFn(subschema) {
|
|
36
|
+
const compiledQueryCache = new WeakMap();
|
|
37
|
+
const transformedRequestCache = new WeakMap();
|
|
38
|
+
const hasBigInt = subschema.schema.getType('BigInt') != null;
|
|
28
39
|
return function subschemaExecute(args) {
|
|
29
40
|
const originalRequest = {
|
|
30
41
|
document: args.document,
|
|
@@ -49,6 +60,7 @@ function getExecuteFn(subschema) {
|
|
|
49
60
|
else if (introspectionQueryType === IntrospectionQueryType.REGULAR) {
|
|
50
61
|
return execute(args);
|
|
51
62
|
}
|
|
63
|
+
const isStream = introspectionQueryType === IntrospectionQueryType.STREAM;
|
|
52
64
|
const delegationContext = {
|
|
53
65
|
subschema,
|
|
54
66
|
subschemaConfig: subschema,
|
|
@@ -64,23 +76,53 @@ function getExecuteFn(subschema) {
|
|
|
64
76
|
};
|
|
65
77
|
let executor = subschema.executor;
|
|
66
78
|
if (executor == null) {
|
|
67
|
-
|
|
79
|
+
if (isStream) {
|
|
80
|
+
executor = createDefaultExecutor(subschema.schema);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
executor = function subschemaExecutor(request) {
|
|
84
|
+
let compiledQuery = compiledQueryCache.get(request.document);
|
|
85
|
+
if (!compiledQuery) {
|
|
86
|
+
const compilationResult = compileQuery(subschema.schema, request.document, request.operationName, {
|
|
87
|
+
customJSONSerializer: !hasBigInt,
|
|
88
|
+
disableLeafSerialization: true,
|
|
89
|
+
});
|
|
90
|
+
if (!isCompiledQuery(compilationResult)) {
|
|
91
|
+
return compilationResult;
|
|
92
|
+
}
|
|
93
|
+
compiledQuery = compilationResult;
|
|
94
|
+
compiledQueryCache.set(request.document, compiledQuery);
|
|
95
|
+
}
|
|
96
|
+
if (operationAST.operation === 'subscription') {
|
|
97
|
+
return compiledQuery.subscribe(request.rootValue, request.context, request.variables);
|
|
98
|
+
}
|
|
99
|
+
return compiledQuery.query(request.rootValue, request.context, request.variables);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
68
102
|
}
|
|
69
103
|
/*
|
|
70
104
|
if (subschema.batch) {
|
|
71
105
|
executor = createBatchingExecutor(executor);
|
|
72
106
|
}
|
|
73
107
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
let transformedRequestAndContext = transformedRequestCache.get(originalRequest.document);
|
|
109
|
+
if (!transformedRequestAndContext) {
|
|
110
|
+
const transformationContext = {};
|
|
111
|
+
const transformedRequest = applyRequestTransforms(originalRequest, delegationContext, transformationContext, subschema.transforms);
|
|
112
|
+
transformedRequestAndContext = {
|
|
113
|
+
transformedRequest,
|
|
114
|
+
transformationContext,
|
|
115
|
+
};
|
|
116
|
+
transformedRequestCache.set(originalRequest.document, transformedRequestAndContext);
|
|
117
|
+
}
|
|
76
118
|
function handleResult(originalResult) {
|
|
77
119
|
if (isAsyncIterable(originalResult)) {
|
|
78
|
-
return mapAsyncIterator(originalResult, singleResult => applyResultTransforms(singleResult, delegationContext, transformationContext, subschema.transforms));
|
|
120
|
+
return mapAsyncIterator(originalResult, singleResult => applyResultTransforms(singleResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms));
|
|
79
121
|
}
|
|
80
|
-
const transformedResult = applyResultTransforms(originalResult, delegationContext, transformationContext, subschema.transforms);
|
|
122
|
+
const transformedResult = applyResultTransforms(originalResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms);
|
|
81
123
|
return transformedResult;
|
|
82
124
|
}
|
|
83
|
-
const originalResult$ = executor(transformedRequest);
|
|
125
|
+
const originalResult$ = executor(transformedRequestAndContext.transformedRequest);
|
|
84
126
|
if (isPromise(originalResult$)) {
|
|
85
127
|
return originalResult$.then(handleResult);
|
|
86
128
|
}
|
package/esm/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BREAK, visit } from 'graphql';
|
|
2
|
+
import { isPromise, memoize1 } from '@graphql-tools/utils';
|
|
2
3
|
export function iterateAsync(iterable, callback, results) {
|
|
3
4
|
const iterator = iterable[Symbol.iterator]();
|
|
4
5
|
function iterate() {
|
|
@@ -22,3 +23,18 @@ export function iterateAsync(iterable, callback, results) {
|
|
|
22
23
|
}
|
|
23
24
|
return iterate();
|
|
24
25
|
}
|
|
26
|
+
export const isStreamOperation = memoize1(function isStreamOperation(astNode) {
|
|
27
|
+
let isStream = false;
|
|
28
|
+
visit(astNode, {
|
|
29
|
+
Field: {
|
|
30
|
+
enter(node) {
|
|
31
|
+
if (node.directives?.some(d => d.name.value === 'stream')) {
|
|
32
|
+
isStream = true;
|
|
33
|
+
return BREAK;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return isStream;
|
|
40
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/runtime",
|
|
3
|
-
"version": "0.96.5
|
|
3
|
+
"version": "0.96.5",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@graphql-mesh/cross-helpers": "^0.4.0",
|
|
7
|
-
"@graphql-mesh/types": "0.95.4
|
|
8
|
-
"@graphql-mesh/utils": "0.95.4
|
|
7
|
+
"@graphql-mesh/types": "^0.95.4",
|
|
8
|
+
"@graphql-mesh/utils": "^0.95.4",
|
|
9
9
|
"@graphql-tools/utils": "^9.2.1 || ^10.0.0",
|
|
10
10
|
"graphql": "*",
|
|
11
11
|
"tslib": "^2.4.0"
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@envelop/core": "^4.0.0",
|
|
15
15
|
"@envelop/extended-validation": "^3.0.0",
|
|
16
|
+
"@envelop/graphql-jit": "^6.0.2",
|
|
16
17
|
"@graphql-mesh/string-interpolation": "^0.5.1",
|
|
17
18
|
"@graphql-tools/batch-delegate": "^9.0.0",
|
|
18
19
|
"@graphql-tools/delegate": "^10.0.0",
|
|
19
20
|
"@graphql-tools/wrap": "^10.0.0",
|
|
20
|
-
"@whatwg-node/fetch": "^0.9.0"
|
|
21
|
+
"@whatwg-node/fetch": "^0.9.0",
|
|
22
|
+
"graphql-jit": "^0.8.4"
|
|
21
23
|
},
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
package/typings/utils.d.cts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
+
import { ASTNode } from 'graphql';
|
|
1
2
|
export declare function iterateAsync<TInput, TOutput>(iterable: Iterable<TInput>, callback: (input: TInput) => Promise<TOutput> | TOutput, results?: TOutput[]): Promise<void> | void;
|
|
3
|
+
export declare const isStreamOperation: (astNode: ASTNode) => boolean;
|
package/typings/utils.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
+
import { ASTNode } from 'graphql';
|
|
1
2
|
export declare function iterateAsync<TInput, TOutput>(iterable: Iterable<TInput>, callback: (input: TInput) => Promise<TOutput> | TOutput, results?: TOutput[]): Promise<void> | void;
|
|
3
|
+
export declare const isStreamOperation: (astNode: ASTNode) => boolean;
|