@graphql-tools/delegate 10.2.0 → 10.2.1-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8
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/CHANGELOG.md +11 -0
- package/dist/index.cjs +102 -157
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +100 -157
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @graphql-tools/delegate
|
|
2
2
|
|
|
3
|
+
## 10.2.1-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#164](https://github.com/graphql-hive/gateway/pull/164) [`310613d`](https://github.com/graphql-hive/gateway/commit/310613d68d1df3e2bceafbd0730084a4c83527bf) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates:
|
|
8
|
+
|
|
9
|
+
- Updated dependency [`@graphql-tools/utils@^10.6.0` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.6.0) (from `^10.5.6`, in `dependencies`)
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`310613d`](https://github.com/graphql-hive/gateway/commit/310613d68d1df3e2bceafbd0730084a4c83527bf)]:
|
|
12
|
+
- @graphql-tools/batch-execute@9.0.7-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8
|
|
13
|
+
|
|
3
14
|
## 10.2.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -57,18 +57,6 @@ class Subschema {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function createDeferred() {
|
|
61
|
-
if (Promise.withResolvers) {
|
|
62
|
-
return Promise.withResolvers();
|
|
63
|
-
}
|
|
64
|
-
let resolve;
|
|
65
|
-
let reject;
|
|
66
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
67
|
-
resolve = _resolve;
|
|
68
|
-
reject = _reject;
|
|
69
|
-
});
|
|
70
|
-
return { promise, resolve, reject };
|
|
71
|
-
}
|
|
72
60
|
const leftOverByDelegationPlan = /* @__PURE__ */ new WeakMap();
|
|
73
61
|
const PLAN_LEFT_OVER = Symbol("PLAN_LEFT_OVER");
|
|
74
62
|
function getPlanLeftOverFromParent(parent) {
|
|
@@ -118,31 +106,22 @@ function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
|
|
|
118
106
|
if (leftOver) {
|
|
119
107
|
object[PLAN_LEFT_OVER] = leftOver;
|
|
120
108
|
}
|
|
121
|
-
|
|
122
|
-
(
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
return utils.mapMaybePromise(
|
|
110
|
+
delegationMaps.reduce(
|
|
111
|
+
(prev, delegationMap) => utils.mapMaybePromise(
|
|
112
|
+
prev,
|
|
113
|
+
() => executeDelegationStage(
|
|
125
114
|
mergedTypeInfo,
|
|
126
115
|
delegationMap,
|
|
127
116
|
object,
|
|
128
117
|
context,
|
|
129
118
|
info
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return executeFn();
|
|
136
|
-
},
|
|
137
|
-
void 0
|
|
119
|
+
)
|
|
120
|
+
),
|
|
121
|
+
void 0
|
|
122
|
+
),
|
|
123
|
+
() => object
|
|
138
124
|
);
|
|
139
|
-
function handleDelegationPlanResult() {
|
|
140
|
-
return object;
|
|
141
|
-
}
|
|
142
|
-
if (utils.isPromise(res$)) {
|
|
143
|
-
return res$.then(handleDelegationPlanResult);
|
|
144
|
-
}
|
|
145
|
-
return handleDelegationPlanResult();
|
|
146
125
|
}
|
|
147
126
|
function handleResolverResult(resolverResult, subschema, selectionSet, object, combinedFieldSubschemaMap, info, path, combinedErrors) {
|
|
148
127
|
if (resolverResult instanceof Error || resolverResult == null) {
|
|
@@ -318,19 +297,18 @@ function resolveExternalValue(result, unpathedErrors, subschema, context, info,
|
|
|
318
297
|
skipTypeMerging
|
|
319
298
|
);
|
|
320
299
|
if (info && graphql.isAbstractType(type)) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
|
|
300
|
+
return utils.mapMaybePromise(
|
|
301
|
+
result$,
|
|
302
|
+
function checkAbstractResolvedCorrectly(result2) {
|
|
303
|
+
if (result2.__typename != null) {
|
|
304
|
+
const resolvedType = info.schema.getType(result2.__typename);
|
|
305
|
+
if (!resolvedType) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
326
308
|
}
|
|
309
|
+
return result2;
|
|
327
310
|
}
|
|
328
|
-
|
|
329
|
-
};
|
|
330
|
-
if (utils.isPromise(result$)) {
|
|
331
|
-
return result$.then(checkAbstractResolvedCorrectly2);
|
|
332
|
-
}
|
|
333
|
-
return checkAbstractResolvedCorrectly2(result$);
|
|
311
|
+
);
|
|
334
312
|
}
|
|
335
313
|
return result$;
|
|
336
314
|
} else if (graphql.isListType(type)) {
|
|
@@ -1843,7 +1821,7 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
1843
1821
|
missingDeferredFields
|
|
1844
1822
|
);
|
|
1845
1823
|
}
|
|
1846
|
-
const deferred = createDeferred();
|
|
1824
|
+
const deferred = utils.createDeferred();
|
|
1847
1825
|
missingDeferredFields.set(responseKey, deferred);
|
|
1848
1826
|
const stitchingInfo = info.schema.extensions?.["stitchingInfo"];
|
|
1849
1827
|
const parentTypeName = parent?.__typename || info.parentType.name;
|
|
@@ -1876,15 +1854,11 @@ function handleResult(parent, responseKey, context, info) {
|
|
|
1876
1854
|
);
|
|
1877
1855
|
const leftOver = getPlanLeftOverFromParent(parent);
|
|
1878
1856
|
if (leftOver) {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
});
|
|
1885
|
-
}
|
|
1886
|
-
parent[responseKey] = resolvedData$;
|
|
1887
|
-
handleLeftOver(parent, context, info, leftOver);
|
|
1857
|
+
return utils.mapMaybePromise(resolvedData$, (resolvedData) => {
|
|
1858
|
+
parent[responseKey] = resolvedData;
|
|
1859
|
+
handleLeftOver(parent, context, info, leftOver);
|
|
1860
|
+
return resolvedData;
|
|
1861
|
+
});
|
|
1888
1862
|
}
|
|
1889
1863
|
return resolvedData$;
|
|
1890
1864
|
}
|
|
@@ -1916,24 +1890,9 @@ function handleLeftOver(parent, context, info, leftOver) {
|
|
|
1916
1890
|
(selectionSet2) => selectionSet2.selections
|
|
1917
1891
|
)
|
|
1918
1892
|
};
|
|
1919
|
-
|
|
1920
|
-
if (utils.isPromise(flattenedParent$)) {
|
|
1921
|
-
flattenedParent$.then((flattenedParent) => {
|
|
1922
|
-
handleFlattenedParent(
|
|
1923
|
-
flattenedParent,
|
|
1924
|
-
parent,
|
|
1925
|
-
possibleSubschema,
|
|
1926
|
-
selectionSet,
|
|
1927
|
-
leftOver,
|
|
1928
|
-
stitchingInfo,
|
|
1929
|
-
parentTypeName,
|
|
1930
|
-
context,
|
|
1931
|
-
info
|
|
1932
|
-
);
|
|
1933
|
-
});
|
|
1934
|
-
} else {
|
|
1893
|
+
utils.mapMaybePromise(flattenPromise(parent), (flattenedParent) => {
|
|
1935
1894
|
handleFlattenedParent(
|
|
1936
|
-
flattenedParent
|
|
1895
|
+
flattenedParent,
|
|
1937
1896
|
parent,
|
|
1938
1897
|
possibleSubschema,
|
|
1939
1898
|
selectionSet,
|
|
@@ -1943,7 +1902,7 @@ function handleLeftOver(parent, context, info, leftOver) {
|
|
|
1943
1902
|
context,
|
|
1944
1903
|
info
|
|
1945
1904
|
);
|
|
1946
|
-
}
|
|
1905
|
+
});
|
|
1947
1906
|
}
|
|
1948
1907
|
}
|
|
1949
1908
|
}
|
|
@@ -1956,13 +1915,13 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
|
|
|
1956
1915
|
possibleSubschema
|
|
1957
1916
|
);
|
|
1958
1917
|
if (resolver) {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1918
|
+
Object.assign(leftOverParent, flattenedParent);
|
|
1919
|
+
const selectionSet2 = {
|
|
1920
|
+
kind: graphql.Kind.SELECTION_SET,
|
|
1921
|
+
selections: missingFieldNodes
|
|
1922
|
+
};
|
|
1923
|
+
utils.mapMaybePromise(
|
|
1924
|
+
resolver(
|
|
1966
1925
|
leftOverParent,
|
|
1967
1926
|
context,
|
|
1968
1927
|
info,
|
|
@@ -1970,24 +1929,10 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
|
|
|
1970
1929
|
selectionSet2,
|
|
1971
1930
|
info.parentType,
|
|
1972
1931
|
info.parentType
|
|
1973
|
-
)
|
|
1974
|
-
|
|
1975
|
-
resolverResult$.then(
|
|
1976
|
-
(resolverResult) => handleDeferredResolverResult(
|
|
1977
|
-
resolverResult,
|
|
1978
|
-
possibleSubschema,
|
|
1979
|
-
selectionSet2,
|
|
1980
|
-
leftOverParent,
|
|
1981
|
-
leftOver,
|
|
1982
|
-
context,
|
|
1983
|
-
info
|
|
1984
|
-
)
|
|
1985
|
-
).catch(
|
|
1986
|
-
(error) => handleDeferredResolverFailure(leftOver, leftOverParent, error)
|
|
1987
|
-
);
|
|
1988
|
-
} else {
|
|
1932
|
+
),
|
|
1933
|
+
(resolverResult) => {
|
|
1989
1934
|
handleDeferredResolverResult(
|
|
1990
|
-
resolverResult
|
|
1935
|
+
resolverResult,
|
|
1991
1936
|
possibleSubschema,
|
|
1992
1937
|
selectionSet2,
|
|
1993
1938
|
leftOverParent,
|
|
@@ -1995,10 +1940,9 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
|
|
|
1995
1940
|
context,
|
|
1996
1941
|
info
|
|
1997
1942
|
);
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
}
|
|
1943
|
+
},
|
|
1944
|
+
(error) => handleDeferredResolverFailure(leftOver, leftOverParent, error)
|
|
1945
|
+
);
|
|
2002
1946
|
}
|
|
2003
1947
|
}
|
|
2004
1948
|
} else {
|
|
@@ -2300,74 +2244,72 @@ function delegateRequest(options) {
|
|
|
2300
2244
|
validateRequest(delegationContext, processedRequest.document);
|
|
2301
2245
|
}
|
|
2302
2246
|
const executor = getExecutor(delegationContext);
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
if (
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
}
|
|
2318
|
-
if (result.incremental) {
|
|
2319
|
-
const data = {};
|
|
2320
|
-
for (const incrementalRes of result.incremental) {
|
|
2321
|
-
if (incrementalRes.items?.length) {
|
|
2322
|
-
for (const item of incrementalRes.items) {
|
|
2323
|
-
merge.dset(
|
|
2324
|
-
data,
|
|
2325
|
-
(incrementalRes.path || []).slice(0, -1),
|
|
2326
|
-
item
|
|
2327
|
-
);
|
|
2328
|
-
}
|
|
2329
|
-
await push(await transformer.transformResult({ data }));
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
if (result.hasNext === false) {
|
|
2247
|
+
return utils.mapMaybePromise(
|
|
2248
|
+
executor(processedRequest),
|
|
2249
|
+
function handleExecutorResult(executorResult) {
|
|
2250
|
+
if (utils.isAsyncIterable(executorResult)) {
|
|
2251
|
+
if (delegationContext.operation === "query" && graphql.isListType(delegationContext.returnType)) {
|
|
2252
|
+
return new repeater.Repeater(async (push, stop) => {
|
|
2253
|
+
const pushed = /* @__PURE__ */ new WeakSet();
|
|
2254
|
+
let stopped = false;
|
|
2255
|
+
stop.finally(() => {
|
|
2256
|
+
stopped = true;
|
|
2257
|
+
});
|
|
2258
|
+
try {
|
|
2259
|
+
for await (const result of executorResult) {
|
|
2260
|
+
if (stopped) {
|
|
2333
2261
|
break;
|
|
2334
|
-
} else {
|
|
2335
|
-
continue;
|
|
2336
2262
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2263
|
+
if (result.incremental) {
|
|
2264
|
+
const data = {};
|
|
2265
|
+
for (const incrementalRes of result.incremental) {
|
|
2266
|
+
if (incrementalRes.items?.length) {
|
|
2267
|
+
for (const item of incrementalRes.items) {
|
|
2268
|
+
merge.dset(
|
|
2269
|
+
data,
|
|
2270
|
+
(incrementalRes.path || []).slice(0, -1),
|
|
2271
|
+
item
|
|
2272
|
+
);
|
|
2273
|
+
}
|
|
2274
|
+
await push(await transformer.transformResult({ data }));
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
if (result.hasNext === false) {
|
|
2342
2278
|
break;
|
|
2279
|
+
} else {
|
|
2280
|
+
continue;
|
|
2343
2281
|
}
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2282
|
+
}
|
|
2283
|
+
const transformedResult = await transformer.transformResult(result);
|
|
2284
|
+
if (Array.isArray(transformedResult)) {
|
|
2285
|
+
for (const individualResult$ of transformedResult) {
|
|
2286
|
+
if (stopped) {
|
|
2287
|
+
break;
|
|
2288
|
+
}
|
|
2289
|
+
const individualResult = await individualResult$;
|
|
2290
|
+
if (!pushed.has(individualResult)) {
|
|
2291
|
+
pushed.add(individualResult);
|
|
2292
|
+
await push(individualResult);
|
|
2293
|
+
}
|
|
2348
2294
|
}
|
|
2295
|
+
} else {
|
|
2296
|
+
await push(await transformedResult);
|
|
2349
2297
|
}
|
|
2350
|
-
} else {
|
|
2351
|
-
await push(await transformedResult);
|
|
2352
2298
|
}
|
|
2299
|
+
stop();
|
|
2300
|
+
} catch (error) {
|
|
2301
|
+
stop(error);
|
|
2353
2302
|
}
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
return utils.mapAsyncIterator(
|
|
2306
|
+
executorResult,
|
|
2307
|
+
(result) => transformer.transformResult(result)
|
|
2308
|
+
);
|
|
2359
2309
|
}
|
|
2360
|
-
return
|
|
2361
|
-
executorResult,
|
|
2362
|
-
(result) => transformer.transformResult(result)
|
|
2363
|
-
);
|
|
2310
|
+
return transformer.transformResult(executorResult);
|
|
2364
2311
|
}
|
|
2365
|
-
|
|
2366
|
-
}
|
|
2367
|
-
if (utils.isPromise(result$)) {
|
|
2368
|
-
return result$.then(handleExecutorResult);
|
|
2369
|
-
}
|
|
2370
|
-
return handleExecutorResult(result$);
|
|
2312
|
+
);
|
|
2371
2313
|
}
|
|
2372
2314
|
function getDelegationContext({
|
|
2373
2315
|
request,
|
|
@@ -2640,6 +2582,10 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
|
|
|
2640
2582
|
});
|
|
2641
2583
|
}
|
|
2642
2584
|
|
|
2585
|
+
Object.defineProperty(exports, "createDeferred", {
|
|
2586
|
+
enumerable: true,
|
|
2587
|
+
get: function () { return utils.createDeferred; }
|
|
2588
|
+
});
|
|
2643
2589
|
exports.FIELD_SUBSCHEMA_MAP_SYMBOL = FIELD_SUBSCHEMA_MAP_SYMBOL;
|
|
2644
2590
|
exports.OBJECT_SUBSCHEMA_SYMBOL = OBJECT_SUBSCHEMA_SYMBOL;
|
|
2645
2591
|
exports.PLAN_LEFT_OVER = PLAN_LEFT_OVER;
|
|
@@ -2650,7 +2596,6 @@ exports.annotateExternalObject = annotateExternalObject;
|
|
|
2650
2596
|
exports.applySchemaTransforms = applySchemaTransforms;
|
|
2651
2597
|
exports.cloneSubschemaConfig = cloneSubschemaConfig;
|
|
2652
2598
|
exports.createDefaultExecutor = createDefaultExecutor;
|
|
2653
|
-
exports.createDeferred = createDeferred;
|
|
2654
2599
|
exports.createRequest = createRequest;
|
|
2655
2600
|
exports.defaultMergedResolver = defaultMergedResolver;
|
|
2656
2601
|
exports.delegateRequest = delegateRequest;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ExecutionRequest, ExecutionResult, Executor, MaybePromise } from '@graphql-tools/utils';
|
|
1
|
+
import { ExecutionRequest, ExecutionResult, Executor, MaybePromise, PromiseWithResolvers } from '@graphql-tools/utils';
|
|
2
|
+
export { createDeferred } from '@graphql-tools/utils';
|
|
2
3
|
import * as graphql from 'graphql';
|
|
3
4
|
import { GraphQLSchema, OperationTypeNode, GraphQLResolveInfo, GraphQLOutputType, GraphQLError, SelectionSetNode, FieldNode, GraphQLObjectType, FragmentDefinitionNode, VariableDefinitionNode, GraphQLNamedType, GraphQLFieldResolver, GraphQLNamedOutputType, GraphQLInterfaceType, SelectionNode, GraphQLField } from 'graphql';
|
|
4
5
|
import DataLoader from 'dataloader';
|
|
@@ -206,7 +207,7 @@ declare const extractUnavailableFields: (schema: GraphQLSchema, field: GraphQLFi
|
|
|
206
207
|
declare function subtractSelectionSets(selectionSetA: SelectionSetNode, selectionSetB: SelectionSetNode): SelectionSetNode;
|
|
207
208
|
|
|
208
209
|
type Deferred<T = unknown> = PromiseWithResolvers<T>;
|
|
209
|
-
|
|
210
|
+
|
|
210
211
|
interface DelegationPlanLeftOver {
|
|
211
212
|
unproxiableFieldNodes: Array<FieldNode>;
|
|
212
213
|
nonProxiableSubschemas: Array<Subschema>;
|
|
@@ -217,4 +218,4 @@ declare const leftOverByDelegationPlan: WeakMap<Map<Subschema<any, any, any, Rec
|
|
|
217
218
|
declare const PLAN_LEFT_OVER: unique symbol;
|
|
218
219
|
declare function getPlanLeftOverFromParent(parent: any): DelegationPlanLeftOver | undefined;
|
|
219
220
|
|
|
220
|
-
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver, type ExternalObject, FIELD_SUBSCHEMA_MAP_SYMBOL, type ICreateProxyingResolverOptions, type ICreateRequest, type IDelegateRequestOptions, type IDelegateToSchemaOptions, type MergedFieldConfig, type MergedTypeConfig, type MergedTypeEntryPoint, type MergedTypeInfo, type MergedTypeResolver, type MergedTypeResolverOptions, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, type RequestTransform, type ResultTransform, type SchemaTransform, type StitchingInfo, Subschema, type SubschemaConfig, type Transform, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor,
|
|
221
|
+
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver, type ExternalObject, FIELD_SUBSCHEMA_MAP_SYMBOL, type ICreateProxyingResolverOptions, type ICreateRequest, type IDelegateRequestOptions, type IDelegateToSchemaOptions, type MergedFieldConfig, type MergedTypeConfig, type MergedTypeEntryPoint, type MergedTypeInfo, type MergedTypeResolver, type MergedTypeResolverOptions, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, type RequestTransform, type ResultTransform, type SchemaTransform, type StitchingInfo, Subschema, type SubschemaConfig, type Transform, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, extractUnavailableFields, extractUnavailableFieldsFromSelectionSet, getActualFieldNodes, getDelegatingOperation, getPlanLeftOverFromParent, getSubschema, getUnpathedErrors, handleResolverResult, isExternalObject, isSubschema, isSubschemaConfig, leftOverByDelegationPlan, mergeFields, resolveExternalValue, subtractSelectionSets };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ExecutionRequest, ExecutionResult, Executor, MaybePromise } from '@graphql-tools/utils';
|
|
1
|
+
import { ExecutionRequest, ExecutionResult, Executor, MaybePromise, PromiseWithResolvers } from '@graphql-tools/utils';
|
|
2
|
+
export { createDeferred } from '@graphql-tools/utils';
|
|
2
3
|
import * as graphql from 'graphql';
|
|
3
4
|
import { GraphQLSchema, OperationTypeNode, GraphQLResolveInfo, GraphQLOutputType, GraphQLError, SelectionSetNode, FieldNode, GraphQLObjectType, FragmentDefinitionNode, VariableDefinitionNode, GraphQLNamedType, GraphQLFieldResolver, GraphQLNamedOutputType, GraphQLInterfaceType, SelectionNode, GraphQLField } from 'graphql';
|
|
4
5
|
import DataLoader from 'dataloader';
|
|
@@ -206,7 +207,7 @@ declare const extractUnavailableFields: (schema: GraphQLSchema, field: GraphQLFi
|
|
|
206
207
|
declare function subtractSelectionSets(selectionSetA: SelectionSetNode, selectionSetB: SelectionSetNode): SelectionSetNode;
|
|
207
208
|
|
|
208
209
|
type Deferred<T = unknown> = PromiseWithResolvers<T>;
|
|
209
|
-
|
|
210
|
+
|
|
210
211
|
interface DelegationPlanLeftOver {
|
|
211
212
|
unproxiableFieldNodes: Array<FieldNode>;
|
|
212
213
|
nonProxiableSubschemas: Array<Subschema>;
|
|
@@ -217,4 +218,4 @@ declare const leftOverByDelegationPlan: WeakMap<Map<Subschema<any, any, any, Rec
|
|
|
217
218
|
declare const PLAN_LEFT_OVER: unique symbol;
|
|
218
219
|
declare function getPlanLeftOverFromParent(parent: any): DelegationPlanLeftOver | undefined;
|
|
219
220
|
|
|
220
|
-
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver, type ExternalObject, FIELD_SUBSCHEMA_MAP_SYMBOL, type ICreateProxyingResolverOptions, type ICreateRequest, type IDelegateRequestOptions, type IDelegateToSchemaOptions, type MergedFieldConfig, type MergedTypeConfig, type MergedTypeEntryPoint, type MergedTypeInfo, type MergedTypeResolver, type MergedTypeResolverOptions, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, type RequestTransform, type ResultTransform, type SchemaTransform, type StitchingInfo, Subschema, type SubschemaConfig, type Transform, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor,
|
|
221
|
+
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver, type ExternalObject, FIELD_SUBSCHEMA_MAP_SYMBOL, type ICreateProxyingResolverOptions, type ICreateRequest, type IDelegateRequestOptions, type IDelegateToSchemaOptions, type MergedFieldConfig, type MergedTypeConfig, type MergedTypeEntryPoint, type MergedTypeInfo, type MergedTypeResolver, type MergedTypeResolverOptions, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, type RequestTransform, type ResultTransform, type SchemaTransform, type StitchingInfo, Subschema, type SubschemaConfig, type Transform, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, extractUnavailableFields, extractUnavailableFieldsFromSelectionSet, getActualFieldNodes, getDelegatingOperation, getPlanLeftOverFromParent, getSubschema, getUnpathedErrors, handleResolverResult, isExternalObject, isSubschema, isSubschemaConfig, leftOverByDelegationPlan, mergeFields, resolveExternalValue, subtractSelectionSets };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { memoize2, memoize1,
|
|
1
|
+
import { memoize2, memoize1, mapMaybePromise, collectFields, relocatedError, mergeDeep, pathToArray, isPromise, getResponseKeyFromInfo, getDefinedRootType, createVariableNameGenerator, updateArgument, serializeInputValue, createGraphQLError, implementsAbstractType, getRootTypeNames, createDeferred, isAsyncIterable, mapAsyncIterator, getOperationASTFromRequest, memoize4 } from '@graphql-tools/utils';
|
|
2
|
+
export { createDeferred } from '@graphql-tools/utils';
|
|
2
3
|
import { GraphQLError, locatedError, isAbstractType, getNullableType, isLeafType, isCompositeType, isListType, responsePathAsArray, Kind, versionInfo, TypeInfo, visit, visitWithTypeInfo, isObjectType, isInterfaceType, TypeNameMetaFieldDef, isUnionType, getNamedType, isNullableType, typeFromAST, defaultFieldResolver, validate } from 'graphql';
|
|
3
4
|
import { CRITICAL_ERROR, normalizedExecutor } from '@graphql-tools/executor';
|
|
4
5
|
import { getBatchingExecutor } from '@graphql-tools/batch-execute';
|
|
@@ -55,18 +56,6 @@ class Subschema {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
function createDeferred() {
|
|
59
|
-
if (Promise.withResolvers) {
|
|
60
|
-
return Promise.withResolvers();
|
|
61
|
-
}
|
|
62
|
-
let resolve;
|
|
63
|
-
let reject;
|
|
64
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
65
|
-
resolve = _resolve;
|
|
66
|
-
reject = _reject;
|
|
67
|
-
});
|
|
68
|
-
return { promise, resolve, reject };
|
|
69
|
-
}
|
|
70
59
|
const leftOverByDelegationPlan = /* @__PURE__ */ new WeakMap();
|
|
71
60
|
const PLAN_LEFT_OVER = Symbol("PLAN_LEFT_OVER");
|
|
72
61
|
function getPlanLeftOverFromParent(parent) {
|
|
@@ -116,31 +105,22 @@ function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
|
|
|
116
105
|
if (leftOver) {
|
|
117
106
|
object[PLAN_LEFT_OVER] = leftOver;
|
|
118
107
|
}
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
return mapMaybePromise(
|
|
109
|
+
delegationMaps.reduce(
|
|
110
|
+
(prev, delegationMap) => mapMaybePromise(
|
|
111
|
+
prev,
|
|
112
|
+
() => executeDelegationStage(
|
|
123
113
|
mergedTypeInfo,
|
|
124
114
|
delegationMap,
|
|
125
115
|
object,
|
|
126
116
|
context,
|
|
127
117
|
info
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return executeFn();
|
|
134
|
-
},
|
|
135
|
-
void 0
|
|
118
|
+
)
|
|
119
|
+
),
|
|
120
|
+
void 0
|
|
121
|
+
),
|
|
122
|
+
() => object
|
|
136
123
|
);
|
|
137
|
-
function handleDelegationPlanResult() {
|
|
138
|
-
return object;
|
|
139
|
-
}
|
|
140
|
-
if (isPromise(res$)) {
|
|
141
|
-
return res$.then(handleDelegationPlanResult);
|
|
142
|
-
}
|
|
143
|
-
return handleDelegationPlanResult();
|
|
144
124
|
}
|
|
145
125
|
function handleResolverResult(resolverResult, subschema, selectionSet, object, combinedFieldSubschemaMap, info, path, combinedErrors) {
|
|
146
126
|
if (resolverResult instanceof Error || resolverResult == null) {
|
|
@@ -316,19 +296,18 @@ function resolveExternalValue(result, unpathedErrors, subschema, context, info,
|
|
|
316
296
|
skipTypeMerging
|
|
317
297
|
);
|
|
318
298
|
if (info && isAbstractType(type)) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
299
|
+
return mapMaybePromise(
|
|
300
|
+
result$,
|
|
301
|
+
function checkAbstractResolvedCorrectly(result2) {
|
|
302
|
+
if (result2.__typename != null) {
|
|
303
|
+
const resolvedType = info.schema.getType(result2.__typename);
|
|
304
|
+
if (!resolvedType) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
324
307
|
}
|
|
308
|
+
return result2;
|
|
325
309
|
}
|
|
326
|
-
|
|
327
|
-
};
|
|
328
|
-
if (isPromise(result$)) {
|
|
329
|
-
return result$.then(checkAbstractResolvedCorrectly2);
|
|
330
|
-
}
|
|
331
|
-
return checkAbstractResolvedCorrectly2(result$);
|
|
310
|
+
);
|
|
332
311
|
}
|
|
333
312
|
return result$;
|
|
334
313
|
} else if (isListType(type)) {
|
|
@@ -1874,15 +1853,11 @@ function handleResult(parent, responseKey, context, info) {
|
|
|
1874
1853
|
);
|
|
1875
1854
|
const leftOver = getPlanLeftOverFromParent(parent);
|
|
1876
1855
|
if (leftOver) {
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
parent[responseKey] = resolvedData$;
|
|
1885
|
-
handleLeftOver(parent, context, info, leftOver);
|
|
1856
|
+
return mapMaybePromise(resolvedData$, (resolvedData) => {
|
|
1857
|
+
parent[responseKey] = resolvedData;
|
|
1858
|
+
handleLeftOver(parent, context, info, leftOver);
|
|
1859
|
+
return resolvedData;
|
|
1860
|
+
});
|
|
1886
1861
|
}
|
|
1887
1862
|
return resolvedData$;
|
|
1888
1863
|
}
|
|
@@ -1914,24 +1889,9 @@ function handleLeftOver(parent, context, info, leftOver) {
|
|
|
1914
1889
|
(selectionSet2) => selectionSet2.selections
|
|
1915
1890
|
)
|
|
1916
1891
|
};
|
|
1917
|
-
|
|
1918
|
-
if (isPromise(flattenedParent$)) {
|
|
1919
|
-
flattenedParent$.then((flattenedParent) => {
|
|
1920
|
-
handleFlattenedParent(
|
|
1921
|
-
flattenedParent,
|
|
1922
|
-
parent,
|
|
1923
|
-
possibleSubschema,
|
|
1924
|
-
selectionSet,
|
|
1925
|
-
leftOver,
|
|
1926
|
-
stitchingInfo,
|
|
1927
|
-
parentTypeName,
|
|
1928
|
-
context,
|
|
1929
|
-
info
|
|
1930
|
-
);
|
|
1931
|
-
});
|
|
1932
|
-
} else {
|
|
1892
|
+
mapMaybePromise(flattenPromise(parent), (flattenedParent) => {
|
|
1933
1893
|
handleFlattenedParent(
|
|
1934
|
-
flattenedParent
|
|
1894
|
+
flattenedParent,
|
|
1935
1895
|
parent,
|
|
1936
1896
|
possibleSubschema,
|
|
1937
1897
|
selectionSet,
|
|
@@ -1941,7 +1901,7 @@ function handleLeftOver(parent, context, info, leftOver) {
|
|
|
1941
1901
|
context,
|
|
1942
1902
|
info
|
|
1943
1903
|
);
|
|
1944
|
-
}
|
|
1904
|
+
});
|
|
1945
1905
|
}
|
|
1946
1906
|
}
|
|
1947
1907
|
}
|
|
@@ -1954,13 +1914,13 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
|
|
|
1954
1914
|
possibleSubschema
|
|
1955
1915
|
);
|
|
1956
1916
|
if (resolver) {
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1917
|
+
Object.assign(leftOverParent, flattenedParent);
|
|
1918
|
+
const selectionSet2 = {
|
|
1919
|
+
kind: Kind.SELECTION_SET,
|
|
1920
|
+
selections: missingFieldNodes
|
|
1921
|
+
};
|
|
1922
|
+
mapMaybePromise(
|
|
1923
|
+
resolver(
|
|
1964
1924
|
leftOverParent,
|
|
1965
1925
|
context,
|
|
1966
1926
|
info,
|
|
@@ -1968,24 +1928,10 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
|
|
|
1968
1928
|
selectionSet2,
|
|
1969
1929
|
info.parentType,
|
|
1970
1930
|
info.parentType
|
|
1971
|
-
)
|
|
1972
|
-
|
|
1973
|
-
resolverResult$.then(
|
|
1974
|
-
(resolverResult) => handleDeferredResolverResult(
|
|
1975
|
-
resolverResult,
|
|
1976
|
-
possibleSubschema,
|
|
1977
|
-
selectionSet2,
|
|
1978
|
-
leftOverParent,
|
|
1979
|
-
leftOver,
|
|
1980
|
-
context,
|
|
1981
|
-
info
|
|
1982
|
-
)
|
|
1983
|
-
).catch(
|
|
1984
|
-
(error) => handleDeferredResolverFailure(leftOver, leftOverParent, error)
|
|
1985
|
-
);
|
|
1986
|
-
} else {
|
|
1931
|
+
),
|
|
1932
|
+
(resolverResult) => {
|
|
1987
1933
|
handleDeferredResolverResult(
|
|
1988
|
-
resolverResult
|
|
1934
|
+
resolverResult,
|
|
1989
1935
|
possibleSubschema,
|
|
1990
1936
|
selectionSet2,
|
|
1991
1937
|
leftOverParent,
|
|
@@ -1993,10 +1939,9 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
|
|
|
1993
1939
|
context,
|
|
1994
1940
|
info
|
|
1995
1941
|
);
|
|
1996
|
-
}
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
}
|
|
1942
|
+
},
|
|
1943
|
+
(error) => handleDeferredResolverFailure(leftOver, leftOverParent, error)
|
|
1944
|
+
);
|
|
2000
1945
|
}
|
|
2001
1946
|
}
|
|
2002
1947
|
} else {
|
|
@@ -2298,74 +2243,72 @@ function delegateRequest(options) {
|
|
|
2298
2243
|
validateRequest(delegationContext, processedRequest.document);
|
|
2299
2244
|
}
|
|
2300
2245
|
const executor = getExecutor(delegationContext);
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
if (
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
}
|
|
2316
|
-
if (result.incremental) {
|
|
2317
|
-
const data = {};
|
|
2318
|
-
for (const incrementalRes of result.incremental) {
|
|
2319
|
-
if (incrementalRes.items?.length) {
|
|
2320
|
-
for (const item of incrementalRes.items) {
|
|
2321
|
-
dset(
|
|
2322
|
-
data,
|
|
2323
|
-
(incrementalRes.path || []).slice(0, -1),
|
|
2324
|
-
item
|
|
2325
|
-
);
|
|
2326
|
-
}
|
|
2327
|
-
await push(await transformer.transformResult({ data }));
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
if (result.hasNext === false) {
|
|
2246
|
+
return mapMaybePromise(
|
|
2247
|
+
executor(processedRequest),
|
|
2248
|
+
function handleExecutorResult(executorResult) {
|
|
2249
|
+
if (isAsyncIterable(executorResult)) {
|
|
2250
|
+
if (delegationContext.operation === "query" && isListType(delegationContext.returnType)) {
|
|
2251
|
+
return new Repeater(async (push, stop) => {
|
|
2252
|
+
const pushed = /* @__PURE__ */ new WeakSet();
|
|
2253
|
+
let stopped = false;
|
|
2254
|
+
stop.finally(() => {
|
|
2255
|
+
stopped = true;
|
|
2256
|
+
});
|
|
2257
|
+
try {
|
|
2258
|
+
for await (const result of executorResult) {
|
|
2259
|
+
if (stopped) {
|
|
2331
2260
|
break;
|
|
2332
|
-
} else {
|
|
2333
|
-
continue;
|
|
2334
2261
|
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2262
|
+
if (result.incremental) {
|
|
2263
|
+
const data = {};
|
|
2264
|
+
for (const incrementalRes of result.incremental) {
|
|
2265
|
+
if (incrementalRes.items?.length) {
|
|
2266
|
+
for (const item of incrementalRes.items) {
|
|
2267
|
+
dset(
|
|
2268
|
+
data,
|
|
2269
|
+
(incrementalRes.path || []).slice(0, -1),
|
|
2270
|
+
item
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
await push(await transformer.transformResult({ data }));
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
if (result.hasNext === false) {
|
|
2340
2277
|
break;
|
|
2278
|
+
} else {
|
|
2279
|
+
continue;
|
|
2341
2280
|
}
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2281
|
+
}
|
|
2282
|
+
const transformedResult = await transformer.transformResult(result);
|
|
2283
|
+
if (Array.isArray(transformedResult)) {
|
|
2284
|
+
for (const individualResult$ of transformedResult) {
|
|
2285
|
+
if (stopped) {
|
|
2286
|
+
break;
|
|
2287
|
+
}
|
|
2288
|
+
const individualResult = await individualResult$;
|
|
2289
|
+
if (!pushed.has(individualResult)) {
|
|
2290
|
+
pushed.add(individualResult);
|
|
2291
|
+
await push(individualResult);
|
|
2292
|
+
}
|
|
2346
2293
|
}
|
|
2294
|
+
} else {
|
|
2295
|
+
await push(await transformedResult);
|
|
2347
2296
|
}
|
|
2348
|
-
} else {
|
|
2349
|
-
await push(await transformedResult);
|
|
2350
2297
|
}
|
|
2298
|
+
stop();
|
|
2299
|
+
} catch (error) {
|
|
2300
|
+
stop(error);
|
|
2351
2301
|
}
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
return mapAsyncIterator(
|
|
2305
|
+
executorResult,
|
|
2306
|
+
(result) => transformer.transformResult(result)
|
|
2307
|
+
);
|
|
2357
2308
|
}
|
|
2358
|
-
return
|
|
2359
|
-
executorResult,
|
|
2360
|
-
(result) => transformer.transformResult(result)
|
|
2361
|
-
);
|
|
2309
|
+
return transformer.transformResult(executorResult);
|
|
2362
2310
|
}
|
|
2363
|
-
|
|
2364
|
-
}
|
|
2365
|
-
if (isPromise(result$)) {
|
|
2366
|
-
return result$.then(handleExecutorResult);
|
|
2367
|
-
}
|
|
2368
|
-
return handleExecutorResult(result$);
|
|
2311
|
+
);
|
|
2369
2312
|
}
|
|
2370
2313
|
function getDelegationContext({
|
|
2371
2314
|
request,
|
|
@@ -2638,4 +2581,4 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
|
|
|
2638
2581
|
});
|
|
2639
2582
|
}
|
|
2640
2583
|
|
|
2641
|
-
export { FIELD_SUBSCHEMA_MAP_SYMBOL, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, Subschema, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor,
|
|
2584
|
+
export { FIELD_SUBSCHEMA_MAP_SYMBOL, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, Subschema, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, extractUnavailableFields, extractUnavailableFieldsFromSelectionSet, getActualFieldNodes, getDelegatingOperation, getPlanLeftOverFromParent, getSubschema, getUnpathedErrors, handleResolverResult, isExternalObject, isSubschema, isSubschemaConfig, leftOverByDelegationPlan, mergeFields, resolveExternalValue, subtractSelectionSets };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.1-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@graphql-tools/batch-execute": "^9.0.
|
|
41
|
+
"@graphql-tools/batch-execute": "^9.0.7-alpha-63d80f9d08b5d8448f4bfb8b04aeff28b977dec8",
|
|
42
42
|
"@graphql-tools/executor": "^1.3.3",
|
|
43
43
|
"@graphql-tools/schema": "^10.0.8",
|
|
44
|
-
"@graphql-tools/utils": "^10.
|
|
44
|
+
"@graphql-tools/utils": "^10.6.0",
|
|
45
45
|
"@repeaterjs/repeater": "^3.0.6",
|
|
46
46
|
"dataloader": "^2.2.2",
|
|
47
47
|
"dset": "^3.1.2",
|