@graphql-tools/delegate 9.0.0-alpha-f6c67111.0 → 9.0.0-alpha-be1b2ebd.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/getMergedParent.d.ts +1 -1
- package/index.js +20 -18
- package/index.mjs +20 -18
- package/package.json +4 -4
package/getMergedParent.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FieldNode, GraphQLResolveInfo, GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ExternalObject, MergedTypeInfo } from './types';
|
|
3
3
|
import { Subschema } from './Subschema';
|
|
4
|
-
export declare function getMergedParent(parent: ExternalObject, context: Record<string, any>, info: GraphQLResolveInfo): Promise<ExternalObject>;
|
|
4
|
+
export declare function getMergedParent(parent: ExternalObject, context: Record<string, any>, info: GraphQLResolveInfo): ExternalObject | Promise<ExternalObject>;
|
|
5
5
|
export declare const buildDelegationPlan: (mergedTypeInfo: MergedTypeInfo, gatewaySchema: GraphQLSchema, sourceSubschema: Subschema, ...fieldNodeArrays: Array<ReadonlyArray<FieldNode>>) => {
|
|
6
6
|
requiredKeys: Record<string, Set<string>>;
|
|
7
7
|
delegationMaps: Array<Map<Subschema, Array<FieldNode>>>;
|
package/index.js
CHANGED
|
@@ -6,8 +6,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
const graphql = require('graphql');
|
|
8
8
|
const utils = require('@graphql-tools/utils');
|
|
9
|
-
const DataLoader = _interopDefault(require('dataloader'));
|
|
10
9
|
const valueOrPromise = require('value-or-promise');
|
|
10
|
+
const DataLoader = _interopDefault(require('dataloader'));
|
|
11
11
|
const batchExecute = require('@graphql-tools/batch-execute');
|
|
12
12
|
|
|
13
13
|
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
@@ -1043,6 +1043,21 @@ function getReturnType(info) {
|
|
|
1043
1043
|
return info.returnType;
|
|
1044
1044
|
}
|
|
1045
1045
|
|
|
1046
|
+
const loaders = new WeakMap();
|
|
1047
|
+
function getMergedParent(parent, context, info) {
|
|
1048
|
+
// In the stitching context, all subschemas are compiled Subschema objects rather than SubschemaConfig objects
|
|
1049
|
+
const sourceSubschema = getObjectSubchema(parent);
|
|
1050
|
+
const mergedTypeInfo = getMergedTypeInfo(info);
|
|
1051
|
+
if (mergedTypeInfo === undefined) {
|
|
1052
|
+
return parent;
|
|
1053
|
+
}
|
|
1054
|
+
let loader = loaders.get(parent);
|
|
1055
|
+
if (loader === undefined) {
|
|
1056
|
+
loader = new DataLoader(fieldNodeArrays => getMergedParentsFromFieldNodes(parent, context, info.schema, fieldNodeArrays, mergedTypeInfo, sourceSubschema));
|
|
1057
|
+
loaders.set(parent, loader);
|
|
1058
|
+
}
|
|
1059
|
+
return loader.load(info.fieldNodes).then(promise => promise);
|
|
1060
|
+
}
|
|
1046
1061
|
const getMergedTypeInfo = utils.memoize1(function getMergedTypeInfo(info) {
|
|
1047
1062
|
var _a;
|
|
1048
1063
|
const schema = info.schema;
|
|
@@ -1057,21 +1072,6 @@ const getMergedTypeInfo = utils.memoize1(function getMergedTypeInfo(info) {
|
|
|
1057
1072
|
}
|
|
1058
1073
|
return mergedTypeInfo;
|
|
1059
1074
|
});
|
|
1060
|
-
const loaders = new WeakMap();
|
|
1061
|
-
async function getMergedParent(parent, context, info) {
|
|
1062
|
-
const mergedTypeInfo = getMergedTypeInfo(info);
|
|
1063
|
-
if (!mergedTypeInfo) {
|
|
1064
|
-
return parent;
|
|
1065
|
-
}
|
|
1066
|
-
// In the stitching context, all subschemas are compiled Subschema objects rather than SubschemaConfig objects
|
|
1067
|
-
const sourceSubschema = getObjectSubchema(parent);
|
|
1068
|
-
let loader = loaders.get(parent);
|
|
1069
|
-
if (loader === undefined) {
|
|
1070
|
-
loader = new DataLoader(fieldNodeArrays => getMergedParentsFromFieldNodes(parent, context, info.schema, fieldNodeArrays, mergedTypeInfo, sourceSubschema));
|
|
1071
|
-
loaders.set(parent, loader);
|
|
1072
|
-
}
|
|
1073
|
-
return loader.load(info.fieldNodes);
|
|
1074
|
-
}
|
|
1075
1075
|
async function getMergedParentsFromFieldNodes(parent, context, gatewaySchema, fieldNodeArrays, mergedTypeInfo, sourceSubschema) {
|
|
1076
1076
|
const { requiredKeys, delegationMaps, stageMap } = buildDelegationPlan(mergedTypeInfo, gatewaySchema, sourceSubschema, ...fieldNodeArrays);
|
|
1077
1077
|
if (!delegationMaps.length) {
|
|
@@ -1384,7 +1384,7 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
1384
1384
|
const initialPossibleFields = getInitialPossibleFields(parent);
|
|
1385
1385
|
if (initialPossibleFields === undefined) {
|
|
1386
1386
|
// TODO: can this be removed in the next major release?
|
|
1387
|
-
// legacy use of
|
|
1387
|
+
// legacy use of delegation without setting transformedSchema
|
|
1388
1388
|
const data = parent[responseKey];
|
|
1389
1389
|
if (data !== undefined) {
|
|
1390
1390
|
return resolveField(parent, responseKey, context, info);
|
|
@@ -1393,7 +1393,9 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
1393
1393
|
else if (info.fieldName in initialPossibleFields) {
|
|
1394
1394
|
return resolveField(parent, responseKey, context, info);
|
|
1395
1395
|
}
|
|
1396
|
-
return
|
|
1396
|
+
return new valueOrPromise.ValueOrPromise(() => getMergedParent(parent, context, info))
|
|
1397
|
+
.then(mergedParent => resolveField(mergedParent, responseKey, context, info))
|
|
1398
|
+
.resolve();
|
|
1397
1399
|
}
|
|
1398
1400
|
function resolveField(parent, responseKey, context, info) {
|
|
1399
1401
|
const initialPath = getInitialPath(parent);
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Kind, isAbstractType, isInterfaceType, TypeInfo, visit, visitWithTypeInfo, getNamedType, isObjectType, versionInfo, TypeNameMetaFieldDef, typeFromAST, locatedError, responsePathAsArray, getNullableType, GraphQLError, isCompositeType, isListType, defaultFieldResolver, getOperationAST, GraphQLSchema, isSchema, validate, subscribe, execute } from 'graphql';
|
|
2
2
|
import { memoize2, implementsAbstractType, getRootTypeNames, getDefinedRootType, createVariableNameGenerator, updateArgument, serializeInputValue, inspect, relocatedError, AggregateError, memoize1, memoize4ofMany, collectFields, memoize3, getResponseKeyFromInfo, isAsyncIterable, mapAsyncIterator } from '@graphql-tools/utils';
|
|
3
|
-
import DataLoader from 'dataloader';
|
|
4
3
|
import { ValueOrPromise } from 'value-or-promise';
|
|
4
|
+
import DataLoader from 'dataloader';
|
|
5
5
|
import { getBatchingExecutor } from '@graphql-tools/batch-execute';
|
|
6
6
|
|
|
7
7
|
function applySchemaTransforms(originalWrappingSchema, subschemaConfig, transformedSchema) {
|
|
@@ -1037,6 +1037,21 @@ function getReturnType(info) {
|
|
|
1037
1037
|
return info.returnType;
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
|
+
const loaders = new WeakMap();
|
|
1041
|
+
function getMergedParent(parent, context, info) {
|
|
1042
|
+
// In the stitching context, all subschemas are compiled Subschema objects rather than SubschemaConfig objects
|
|
1043
|
+
const sourceSubschema = getObjectSubchema(parent);
|
|
1044
|
+
const mergedTypeInfo = getMergedTypeInfo(info);
|
|
1045
|
+
if (mergedTypeInfo === undefined) {
|
|
1046
|
+
return parent;
|
|
1047
|
+
}
|
|
1048
|
+
let loader = loaders.get(parent);
|
|
1049
|
+
if (loader === undefined) {
|
|
1050
|
+
loader = new DataLoader(fieldNodeArrays => getMergedParentsFromFieldNodes(parent, context, info.schema, fieldNodeArrays, mergedTypeInfo, sourceSubschema));
|
|
1051
|
+
loaders.set(parent, loader);
|
|
1052
|
+
}
|
|
1053
|
+
return loader.load(info.fieldNodes).then(promise => promise);
|
|
1054
|
+
}
|
|
1040
1055
|
const getMergedTypeInfo = memoize1(function getMergedTypeInfo(info) {
|
|
1041
1056
|
var _a;
|
|
1042
1057
|
const schema = info.schema;
|
|
@@ -1051,21 +1066,6 @@ const getMergedTypeInfo = memoize1(function getMergedTypeInfo(info) {
|
|
|
1051
1066
|
}
|
|
1052
1067
|
return mergedTypeInfo;
|
|
1053
1068
|
});
|
|
1054
|
-
const loaders = new WeakMap();
|
|
1055
|
-
async function getMergedParent(parent, context, info) {
|
|
1056
|
-
const mergedTypeInfo = getMergedTypeInfo(info);
|
|
1057
|
-
if (!mergedTypeInfo) {
|
|
1058
|
-
return parent;
|
|
1059
|
-
}
|
|
1060
|
-
// In the stitching context, all subschemas are compiled Subschema objects rather than SubschemaConfig objects
|
|
1061
|
-
const sourceSubschema = getObjectSubchema(parent);
|
|
1062
|
-
let loader = loaders.get(parent);
|
|
1063
|
-
if (loader === undefined) {
|
|
1064
|
-
loader = new DataLoader(fieldNodeArrays => getMergedParentsFromFieldNodes(parent, context, info.schema, fieldNodeArrays, mergedTypeInfo, sourceSubschema));
|
|
1065
|
-
loaders.set(parent, loader);
|
|
1066
|
-
}
|
|
1067
|
-
return loader.load(info.fieldNodes);
|
|
1068
|
-
}
|
|
1069
1069
|
async function getMergedParentsFromFieldNodes(parent, context, gatewaySchema, fieldNodeArrays, mergedTypeInfo, sourceSubschema) {
|
|
1070
1070
|
const { requiredKeys, delegationMaps, stageMap } = buildDelegationPlan(mergedTypeInfo, gatewaySchema, sourceSubschema, ...fieldNodeArrays);
|
|
1071
1071
|
if (!delegationMaps.length) {
|
|
@@ -1378,7 +1378,7 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
1378
1378
|
const initialPossibleFields = getInitialPossibleFields(parent);
|
|
1379
1379
|
if (initialPossibleFields === undefined) {
|
|
1380
1380
|
// TODO: can this be removed in the next major release?
|
|
1381
|
-
// legacy use of
|
|
1381
|
+
// legacy use of delegation without setting transformedSchema
|
|
1382
1382
|
const data = parent[responseKey];
|
|
1383
1383
|
if (data !== undefined) {
|
|
1384
1384
|
return resolveField(parent, responseKey, context, info);
|
|
@@ -1387,7 +1387,9 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
1387
1387
|
else if (info.fieldName in initialPossibleFields) {
|
|
1388
1388
|
return resolveField(parent, responseKey, context, info);
|
|
1389
1389
|
}
|
|
1390
|
-
return
|
|
1390
|
+
return new ValueOrPromise(() => getMergedParent(parent, context, info))
|
|
1391
|
+
.then(mergedParent => resolveField(mergedParent, responseKey, context, info))
|
|
1392
|
+
.resolve();
|
|
1391
1393
|
}
|
|
1392
1394
|
function resolveField(parent, responseKey, context, info) {
|
|
1393
1395
|
const initialPath = getInitialPath(parent);
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate",
|
|
3
|
-
"version": "9.0.0-alpha-
|
|
3
|
+
"version": "9.0.0-alpha-be1b2ebd.0",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/batch-execute": "8.1.1-alpha-
|
|
11
|
-
"@graphql-tools/schema": "8.2.1-alpha-
|
|
12
|
-
"@graphql-tools/utils": "9.0.0-alpha-
|
|
10
|
+
"@graphql-tools/batch-execute": "8.1.1-alpha-be1b2ebd.0",
|
|
11
|
+
"@graphql-tools/schema": "8.2.1-alpha-be1b2ebd.0",
|
|
12
|
+
"@graphql-tools/utils": "9.0.0-alpha-be1b2ebd.0",
|
|
13
13
|
"dataloader": "2.0.0",
|
|
14
14
|
"tslib": "~2.3.0",
|
|
15
15
|
"value-or-promise": "1.0.10"
|