@graphql-tools/delegate 9.0.0-alpha-8ae2f1b1.0 → 9.0.0-alpha-881b29e4.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 +23 -29
- package/index.mjs +23 -29
- package/package.json +4 -4
package/getMergedParent.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FieldNode, GraphQLResolveInfo, GraphQLSchema } from 'graphql';
|
|
|
2
2
|
import { ExternalObject, MergedTypeInfo } from './types';
|
|
3
3
|
import { Subschema } from './Subschema';
|
|
4
4
|
export declare function getMergedParent(parent: ExternalObject, context: Record<string, any>, info: GraphQLResolveInfo): Promise<ExternalObject>;
|
|
5
|
-
export declare const buildDelegationPlan: (mergedTypeInfo: MergedTypeInfo,
|
|
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>>>;
|
|
8
8
|
stageMap: Record<string, number>;
|
package/index.js
CHANGED
|
@@ -1043,7 +1043,7 @@ function getReturnType(info) {
|
|
|
1043
1043
|
return info.returnType;
|
|
1044
1044
|
}
|
|
1045
1045
|
|
|
1046
|
-
const
|
|
1046
|
+
const getMergedTypeInfo = utils.memoize1(function getMergedTypeInfo(info) {
|
|
1047
1047
|
var _a;
|
|
1048
1048
|
const schema = info.schema;
|
|
1049
1049
|
const stitchingInfo = (_a = schema.extensions) === null || _a === void 0 ? void 0 : _a['stitchingInfo'];
|
|
@@ -1055,60 +1055,53 @@ const getMergeDetails = utils.memoize1(function getMergeDetails(info) {
|
|
|
1055
1055
|
if (mergedTypeInfo === undefined) {
|
|
1056
1056
|
return;
|
|
1057
1057
|
}
|
|
1058
|
-
return
|
|
1059
|
-
stitchingInfo,
|
|
1060
|
-
mergedTypeInfo,
|
|
1061
|
-
};
|
|
1058
|
+
return mergedTypeInfo;
|
|
1062
1059
|
});
|
|
1063
1060
|
const loaders = new WeakMap();
|
|
1064
1061
|
async function getMergedParent(parent, context, info) {
|
|
1065
|
-
const
|
|
1066
|
-
if (!
|
|
1062
|
+
const mergedTypeInfo = getMergedTypeInfo(info);
|
|
1063
|
+
if (!mergedTypeInfo) {
|
|
1067
1064
|
return parent;
|
|
1068
1065
|
}
|
|
1069
|
-
const { mergedTypeInfo } = mergeDetails;
|
|
1070
1066
|
// In the stitching context, all subschemas are compiled Subschema objects rather than SubschemaConfig objects
|
|
1071
1067
|
const sourceSubschema = getObjectSubchema(parent);
|
|
1072
|
-
const targetSubschemas = mergedTypeInfo.targetSubschemas.get(sourceSubschema);
|
|
1073
|
-
if (targetSubschemas === undefined || targetSubschemas.length === 0) {
|
|
1074
|
-
return parent;
|
|
1075
|
-
}
|
|
1076
1068
|
let loader = loaders.get(parent);
|
|
1077
1069
|
if (loader === undefined) {
|
|
1078
|
-
loader = new DataLoader(
|
|
1070
|
+
loader = new DataLoader(fieldNodeArrays => getMergedParentsFromFieldNodes(parent, context, info.schema, fieldNodeArrays, mergedTypeInfo, sourceSubschema));
|
|
1079
1071
|
loaders.set(parent, loader);
|
|
1080
1072
|
}
|
|
1081
|
-
return loader.load(info);
|
|
1073
|
+
return loader.load(info.fieldNodes);
|
|
1082
1074
|
}
|
|
1083
|
-
async function
|
|
1084
|
-
const { requiredKeys, delegationMaps, stageMap } = buildDelegationPlan(mergedTypeInfo,
|
|
1075
|
+
async function getMergedParentsFromFieldNodes(parent, context, gatewaySchema, fieldNodeArrays, mergedTypeInfo, sourceSubschema) {
|
|
1076
|
+
const { requiredKeys, delegationMaps, stageMap } = buildDelegationPlan(mergedTypeInfo, gatewaySchema, sourceSubschema, ...fieldNodeArrays);
|
|
1085
1077
|
if (!delegationMaps.length) {
|
|
1086
|
-
return Array(
|
|
1078
|
+
return Array(fieldNodeArrays.length).fill(parent);
|
|
1087
1079
|
}
|
|
1088
1080
|
const promises = [];
|
|
1089
1081
|
const parentInfo = getInfo(parent);
|
|
1090
1082
|
const schema = parentInfo.schema;
|
|
1091
1083
|
const type = schema.getType(parent.__typename);
|
|
1092
1084
|
const parentPath = graphql.responsePathAsArray(parentInfo.path);
|
|
1093
|
-
let promise = executeDelegationStage(delegationMaps[0], schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath)
|
|
1085
|
+
let promise = executeDelegationStage(delegationMaps[0], schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath);
|
|
1094
1086
|
promises.push(promise);
|
|
1095
1087
|
for (let i = 1, delegationStage = delegationMaps[i]; i < delegationMaps.length; i++) {
|
|
1096
|
-
promise = promise.then(parent => executeDelegationStage(delegationStage, schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath)
|
|
1088
|
+
promise = promise.then(parent => executeDelegationStage(delegationStage, schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath));
|
|
1097
1089
|
promises.push(promise);
|
|
1098
1090
|
}
|
|
1099
|
-
return
|
|
1100
|
-
const
|
|
1091
|
+
return fieldNodeArrays.map(fieldNodeArray => {
|
|
1092
|
+
const fieldName = fieldNodeArray[0].name.value;
|
|
1093
|
+
const keys = requiredKeys[fieldName];
|
|
1101
1094
|
if (keys === undefined) {
|
|
1102
|
-
const delegationStage = stageMap[
|
|
1095
|
+
const delegationStage = stageMap[fieldName];
|
|
1103
1096
|
if (delegationStage !== undefined) {
|
|
1104
|
-
return promises[delegationStage]
|
|
1097
|
+
return promises[delegationStage];
|
|
1105
1098
|
}
|
|
1106
1099
|
return Promise.resolve(parent);
|
|
1107
1100
|
}
|
|
1108
1101
|
return Promise.all(Array.from(keys.values()).map(fieldName => {
|
|
1109
1102
|
const delegationStage = stageMap[fieldName];
|
|
1110
1103
|
if (delegationStage !== undefined) {
|
|
1111
|
-
return promises[delegationStage]
|
|
1104
|
+
return promises[delegationStage];
|
|
1112
1105
|
}
|
|
1113
1106
|
return Promise.resolve(parent);
|
|
1114
1107
|
})).then(() => parent);
|
|
@@ -1155,12 +1148,12 @@ function calculateDelegationStage(mergedTypeInfo, sourceSubschemas, targetSubsch
|
|
|
1155
1148
|
unproxiableFieldNodes,
|
|
1156
1149
|
};
|
|
1157
1150
|
}
|
|
1158
|
-
const buildDelegationPlan = utils.memoize4ofMany(function buildDelegationPlan(mergedTypeInfo,
|
|
1151
|
+
const buildDelegationPlan = utils.memoize4ofMany(function buildDelegationPlan(mergedTypeInfo, gatewaySchema, sourceSubschema, ...fieldNodeArrays) {
|
|
1159
1152
|
var _a, _b, _c;
|
|
1160
1153
|
const requiredKeys = Object.create(null);
|
|
1161
1154
|
const delegationMaps = [];
|
|
1162
1155
|
const stageMap = Object.create(null);
|
|
1163
|
-
const stitchingInfo = (_a =
|
|
1156
|
+
const stitchingInfo = (_a = gatewaySchema.extensions) === null || _a === void 0 ? void 0 : _a['stitchingInfo'];
|
|
1164
1157
|
if (stitchingInfo == null) {
|
|
1165
1158
|
return { requiredKeys, delegationMaps, stageMap };
|
|
1166
1159
|
}
|
|
@@ -1337,20 +1330,21 @@ async function executeDelegationStage(delegationMap, schema, type, mergedTypeInf
|
|
|
1337
1330
|
}
|
|
1338
1331
|
source = nullResult;
|
|
1339
1332
|
}
|
|
1340
|
-
// TODO: fold this assign into loop below?
|
|
1341
|
-
Object.assign(object, source);
|
|
1342
1333
|
// TODO: is this check necessary or just to make TS happy?
|
|
1343
1334
|
if (!isExternalObject(source)) {
|
|
1344
|
-
|
|
1335
|
+
Object.assign(object, source);
|
|
1336
|
+
return object;
|
|
1345
1337
|
}
|
|
1346
1338
|
const objectSubschema = getObjectSubchema(source);
|
|
1347
1339
|
const subschemaMap = getSubschemaMap(source);
|
|
1348
1340
|
for (const responseKey in source) {
|
|
1341
|
+
object[responseKey] = source[responseKey];
|
|
1349
1342
|
newSubschemaMap[responseKey] = (_a = subschemaMap === null || subschemaMap === void 0 ? void 0 : subschemaMap[responseKey]) !== null && _a !== void 0 ? _a : objectSubschema;
|
|
1350
1343
|
}
|
|
1351
1344
|
unpathedErrors.push(...getUnpathedErrors(source));
|
|
1352
1345
|
}
|
|
1353
1346
|
}));
|
|
1347
|
+
return object;
|
|
1354
1348
|
}
|
|
1355
1349
|
const subschemaTypesContainSelectionSet = utils.memoize3(function subschemaTypesContainSelectionSet(mergedTypeInfo, sourceSubschemas, selectionSet) {
|
|
1356
1350
|
return typesContainSelectionSet(sourceSubschemas.map(sourceSubschema => sourceSubschema.transformedSchema.getType(mergedTypeInfo.typeName)), selectionSet);
|
package/index.mjs
CHANGED
|
@@ -1037,7 +1037,7 @@ function getReturnType(info) {
|
|
|
1037
1037
|
return info.returnType;
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
|
-
const
|
|
1040
|
+
const getMergedTypeInfo = memoize1(function getMergedTypeInfo(info) {
|
|
1041
1041
|
var _a;
|
|
1042
1042
|
const schema = info.schema;
|
|
1043
1043
|
const stitchingInfo = (_a = schema.extensions) === null || _a === void 0 ? void 0 : _a['stitchingInfo'];
|
|
@@ -1049,60 +1049,53 @@ const getMergeDetails = memoize1(function getMergeDetails(info) {
|
|
|
1049
1049
|
if (mergedTypeInfo === undefined) {
|
|
1050
1050
|
return;
|
|
1051
1051
|
}
|
|
1052
|
-
return
|
|
1053
|
-
stitchingInfo,
|
|
1054
|
-
mergedTypeInfo,
|
|
1055
|
-
};
|
|
1052
|
+
return mergedTypeInfo;
|
|
1056
1053
|
});
|
|
1057
1054
|
const loaders = new WeakMap();
|
|
1058
1055
|
async function getMergedParent(parent, context, info) {
|
|
1059
|
-
const
|
|
1060
|
-
if (!
|
|
1056
|
+
const mergedTypeInfo = getMergedTypeInfo(info);
|
|
1057
|
+
if (!mergedTypeInfo) {
|
|
1061
1058
|
return parent;
|
|
1062
1059
|
}
|
|
1063
|
-
const { mergedTypeInfo } = mergeDetails;
|
|
1064
1060
|
// In the stitching context, all subschemas are compiled Subschema objects rather than SubschemaConfig objects
|
|
1065
1061
|
const sourceSubschema = getObjectSubchema(parent);
|
|
1066
|
-
const targetSubschemas = mergedTypeInfo.targetSubschemas.get(sourceSubschema);
|
|
1067
|
-
if (targetSubschemas === undefined || targetSubschemas.length === 0) {
|
|
1068
|
-
return parent;
|
|
1069
|
-
}
|
|
1070
1062
|
let loader = loaders.get(parent);
|
|
1071
1063
|
if (loader === undefined) {
|
|
1072
|
-
loader = new DataLoader(
|
|
1064
|
+
loader = new DataLoader(fieldNodeArrays => getMergedParentsFromFieldNodes(parent, context, info.schema, fieldNodeArrays, mergedTypeInfo, sourceSubschema));
|
|
1073
1065
|
loaders.set(parent, loader);
|
|
1074
1066
|
}
|
|
1075
|
-
return loader.load(info);
|
|
1067
|
+
return loader.load(info.fieldNodes);
|
|
1076
1068
|
}
|
|
1077
|
-
async function
|
|
1078
|
-
const { requiredKeys, delegationMaps, stageMap } = buildDelegationPlan(mergedTypeInfo,
|
|
1069
|
+
async function getMergedParentsFromFieldNodes(parent, context, gatewaySchema, fieldNodeArrays, mergedTypeInfo, sourceSubschema) {
|
|
1070
|
+
const { requiredKeys, delegationMaps, stageMap } = buildDelegationPlan(mergedTypeInfo, gatewaySchema, sourceSubschema, ...fieldNodeArrays);
|
|
1079
1071
|
if (!delegationMaps.length) {
|
|
1080
|
-
return Array(
|
|
1072
|
+
return Array(fieldNodeArrays.length).fill(parent);
|
|
1081
1073
|
}
|
|
1082
1074
|
const promises = [];
|
|
1083
1075
|
const parentInfo = getInfo(parent);
|
|
1084
1076
|
const schema = parentInfo.schema;
|
|
1085
1077
|
const type = schema.getType(parent.__typename);
|
|
1086
1078
|
const parentPath = responsePathAsArray(parentInfo.path);
|
|
1087
|
-
let promise = executeDelegationStage(delegationMaps[0], schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath)
|
|
1079
|
+
let promise = executeDelegationStage(delegationMaps[0], schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath);
|
|
1088
1080
|
promises.push(promise);
|
|
1089
1081
|
for (let i = 1, delegationStage = delegationMaps[i]; i < delegationMaps.length; i++) {
|
|
1090
|
-
promise = promise.then(parent => executeDelegationStage(delegationStage, schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath)
|
|
1082
|
+
promise = promise.then(parent => executeDelegationStage(delegationStage, schema, type, mergedTypeInfo, context, parent, parentInfo, parentPath));
|
|
1091
1083
|
promises.push(promise);
|
|
1092
1084
|
}
|
|
1093
|
-
return
|
|
1094
|
-
const
|
|
1085
|
+
return fieldNodeArrays.map(fieldNodeArray => {
|
|
1086
|
+
const fieldName = fieldNodeArray[0].name.value;
|
|
1087
|
+
const keys = requiredKeys[fieldName];
|
|
1095
1088
|
if (keys === undefined) {
|
|
1096
|
-
const delegationStage = stageMap[
|
|
1089
|
+
const delegationStage = stageMap[fieldName];
|
|
1097
1090
|
if (delegationStage !== undefined) {
|
|
1098
|
-
return promises[delegationStage]
|
|
1091
|
+
return promises[delegationStage];
|
|
1099
1092
|
}
|
|
1100
1093
|
return Promise.resolve(parent);
|
|
1101
1094
|
}
|
|
1102
1095
|
return Promise.all(Array.from(keys.values()).map(fieldName => {
|
|
1103
1096
|
const delegationStage = stageMap[fieldName];
|
|
1104
1097
|
if (delegationStage !== undefined) {
|
|
1105
|
-
return promises[delegationStage]
|
|
1098
|
+
return promises[delegationStage];
|
|
1106
1099
|
}
|
|
1107
1100
|
return Promise.resolve(parent);
|
|
1108
1101
|
})).then(() => parent);
|
|
@@ -1149,12 +1142,12 @@ function calculateDelegationStage(mergedTypeInfo, sourceSubschemas, targetSubsch
|
|
|
1149
1142
|
unproxiableFieldNodes,
|
|
1150
1143
|
};
|
|
1151
1144
|
}
|
|
1152
|
-
const buildDelegationPlan = memoize4ofMany(function buildDelegationPlan(mergedTypeInfo,
|
|
1145
|
+
const buildDelegationPlan = memoize4ofMany(function buildDelegationPlan(mergedTypeInfo, gatewaySchema, sourceSubschema, ...fieldNodeArrays) {
|
|
1153
1146
|
var _a, _b, _c;
|
|
1154
1147
|
const requiredKeys = Object.create(null);
|
|
1155
1148
|
const delegationMaps = [];
|
|
1156
1149
|
const stageMap = Object.create(null);
|
|
1157
|
-
const stitchingInfo = (_a =
|
|
1150
|
+
const stitchingInfo = (_a = gatewaySchema.extensions) === null || _a === void 0 ? void 0 : _a['stitchingInfo'];
|
|
1158
1151
|
if (stitchingInfo == null) {
|
|
1159
1152
|
return { requiredKeys, delegationMaps, stageMap };
|
|
1160
1153
|
}
|
|
@@ -1331,20 +1324,21 @@ async function executeDelegationStage(delegationMap, schema, type, mergedTypeInf
|
|
|
1331
1324
|
}
|
|
1332
1325
|
source = nullResult;
|
|
1333
1326
|
}
|
|
1334
|
-
// TODO: fold this assign into loop below?
|
|
1335
|
-
Object.assign(object, source);
|
|
1336
1327
|
// TODO: is this check necessary or just to make TS happy?
|
|
1337
1328
|
if (!isExternalObject(source)) {
|
|
1338
|
-
|
|
1329
|
+
Object.assign(object, source);
|
|
1330
|
+
return object;
|
|
1339
1331
|
}
|
|
1340
1332
|
const objectSubschema = getObjectSubchema(source);
|
|
1341
1333
|
const subschemaMap = getSubschemaMap(source);
|
|
1342
1334
|
for (const responseKey in source) {
|
|
1335
|
+
object[responseKey] = source[responseKey];
|
|
1343
1336
|
newSubschemaMap[responseKey] = (_a = subschemaMap === null || subschemaMap === void 0 ? void 0 : subschemaMap[responseKey]) !== null && _a !== void 0 ? _a : objectSubschema;
|
|
1344
1337
|
}
|
|
1345
1338
|
unpathedErrors.push(...getUnpathedErrors(source));
|
|
1346
1339
|
}
|
|
1347
1340
|
}));
|
|
1341
|
+
return object;
|
|
1348
1342
|
}
|
|
1349
1343
|
const subschemaTypesContainSelectionSet = memoize3(function subschemaTypesContainSelectionSet(mergedTypeInfo, sourceSubschemas, selectionSet) {
|
|
1350
1344
|
return typesContainSelectionSet(sourceSubschemas.map(sourceSubschema => sourceSubschema.transformedSchema.getType(mergedTypeInfo.typeName)), selectionSet);
|
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-881b29e4.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-881b29e4.0",
|
|
11
|
+
"@graphql-tools/schema": "8.2.1-alpha-881b29e4.0",
|
|
12
|
+
"@graphql-tools/utils": "9.0.0-alpha-881b29e4.0",
|
|
13
13
|
"dataloader": "2.0.0",
|
|
14
14
|
"tslib": "~2.3.0",
|
|
15
15
|
"value-or-promise": "1.0.10"
|