@graphql-tools/delegate 12.0.4 → 12.0.5-alpha-6bcca2bc60aea3f017e008bd95b91f282608f123
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 +7 -0
- package/dist/index.cjs +79 -21
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +80 -22
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @graphql-tools/delegate
|
|
2
2
|
|
|
3
|
+
## 12.0.5-alpha-6bcca2bc60aea3f017e008bd95b91f282608f123
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#1901](https://github.com/graphql-hive/gateway/pull/1901) [`8ee616a`](https://github.com/graphql-hive/gateway/commit/8ee616a668eea6cf2b4539a17642ed1f85a9560d) Thanks [@ardatan](https://github.com/ardatan)! - Do not add required fields if they are already present in the original selection set
|
|
9
|
+
|
|
3
10
|
## 12.0.4
|
|
4
11
|
### Patch Changes
|
|
5
12
|
|
package/dist/index.cjs
CHANGED
|
@@ -1283,7 +1283,7 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1283
1283
|
const fieldNodes = fieldNodesByType[parentTypeName];
|
|
1284
1284
|
if (fieldNodes) {
|
|
1285
1285
|
for (const fieldNode of fieldNodes) {
|
|
1286
|
-
newSelections
|
|
1286
|
+
addSelectionNodeToSelections(newSelections, fieldNode);
|
|
1287
1287
|
}
|
|
1288
1288
|
}
|
|
1289
1289
|
const interfaceExtensions = interfaceExtensionsMap[parentType.name];
|
|
@@ -1300,7 +1300,7 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1300
1300
|
);
|
|
1301
1301
|
const extraPossibleTypes = getExtraPossibleTypes2(typeName);
|
|
1302
1302
|
for (const extraPossibleTypeName of extraPossibleTypes) {
|
|
1303
|
-
newSelections
|
|
1303
|
+
addSelectionNodeToSelections(newSelections, {
|
|
1304
1304
|
...selection,
|
|
1305
1305
|
typeCondition: {
|
|
1306
1306
|
kind: graphql.Kind.NAMED_TYPE,
|
|
@@ -1319,13 +1319,13 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1319
1319
|
const fieldName = subSelection.name.value;
|
|
1320
1320
|
const field = fieldMap[fieldName];
|
|
1321
1321
|
if (!field) {
|
|
1322
|
-
newSelections
|
|
1322
|
+
addSelectionNodeToSelections(newSelections, subSelection);
|
|
1323
1323
|
}
|
|
1324
1324
|
}
|
|
1325
1325
|
}
|
|
1326
1326
|
} else if (!typeInSubschema) {
|
|
1327
1327
|
for (const subSelection of selection.selectionSet.selections) {
|
|
1328
|
-
newSelections
|
|
1328
|
+
addSelectionNodeToSelections(newSelections, subSelection);
|
|
1329
1329
|
}
|
|
1330
1330
|
}
|
|
1331
1331
|
}
|
|
@@ -1334,10 +1334,10 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1334
1334
|
const fieldNodesForTypeName = fieldNodesByField[parentTypeName]?.["__typename"];
|
|
1335
1335
|
if (fieldNodesForTypeName) {
|
|
1336
1336
|
for (const fieldNode of fieldNodesForTypeName) {
|
|
1337
|
-
newSelections
|
|
1337
|
+
addSelectionNodeToSelections(newSelections, fieldNode);
|
|
1338
1338
|
}
|
|
1339
1339
|
}
|
|
1340
|
-
newSelections
|
|
1340
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1341
1341
|
continue;
|
|
1342
1342
|
}
|
|
1343
1343
|
for (const possibleTypeName of possibleTypes) {
|
|
@@ -1347,7 +1347,8 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1347
1347
|
parentType,
|
|
1348
1348
|
maybePossibleType
|
|
1349
1349
|
)) {
|
|
1350
|
-
|
|
1350
|
+
addSelectionNodeToSelections(
|
|
1351
|
+
newSelections,
|
|
1351
1352
|
generateInlineFragment(
|
|
1352
1353
|
possibleTypeName,
|
|
1353
1354
|
selection.selectionSet
|
|
@@ -1356,22 +1357,22 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1356
1357
|
}
|
|
1357
1358
|
}
|
|
1358
1359
|
if (possibleTypes.length === 0) {
|
|
1359
|
-
newSelections
|
|
1360
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1360
1361
|
}
|
|
1361
1362
|
} else {
|
|
1362
|
-
newSelections
|
|
1363
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1363
1364
|
}
|
|
1364
1365
|
} else if (selection.kind === graphql.Kind.FRAGMENT_SPREAD) {
|
|
1365
1366
|
const fragmentName = selection.name.value;
|
|
1366
1367
|
if (!fragmentReplacements[fragmentName]) {
|
|
1367
|
-
newSelections
|
|
1368
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1368
1369
|
continue;
|
|
1369
1370
|
}
|
|
1370
1371
|
for (const replacement of fragmentReplacements[fragmentName]) {
|
|
1371
1372
|
const typeName = replacement.typeName;
|
|
1372
1373
|
const maybeReplacementType = transformedSchema.getType(typeName);
|
|
1373
1374
|
if (maybeReplacementType != null && utils.implementsAbstractType(transformedSchema, parentType, maybeType)) {
|
|
1374
|
-
newSelections
|
|
1375
|
+
addSelectionNodeToSelections(newSelections, {
|
|
1375
1376
|
kind: graphql.Kind.FRAGMENT_SPREAD,
|
|
1376
1377
|
name: {
|
|
1377
1378
|
kind: graphql.Kind.NAME,
|
|
@@ -1382,11 +1383,16 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1382
1383
|
}
|
|
1383
1384
|
} else {
|
|
1384
1385
|
const fieldName = selection.name.value;
|
|
1386
|
+
if (interfaceExtensions?.[fieldName]) {
|
|
1387
|
+
interfaceExtensionFields.push(selection);
|
|
1388
|
+
} else {
|
|
1389
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1390
|
+
}
|
|
1385
1391
|
if (graphql.isAbstractType(parentType)) {
|
|
1386
1392
|
const fieldNodesForTypeName = fieldNodesByField[parentTypeName]?.["__typename"];
|
|
1387
1393
|
if (fieldNodesForTypeName) {
|
|
1388
1394
|
for (const fieldNode of fieldNodesForTypeName) {
|
|
1389
|
-
newSelections
|
|
1395
|
+
addSelectionNodeToSelections(newSelections, fieldNode);
|
|
1390
1396
|
}
|
|
1391
1397
|
}
|
|
1392
1398
|
}
|
|
@@ -1405,20 +1411,15 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1405
1411
|
const selectionSet = selectionSetFn(selection);
|
|
1406
1412
|
if (selectionSet != null) {
|
|
1407
1413
|
for (const selection2 of selectionSet.selections) {
|
|
1408
|
-
newSelections
|
|
1414
|
+
addSelectionNodeToSelections(newSelections, selection2);
|
|
1409
1415
|
}
|
|
1410
1416
|
}
|
|
1411
1417
|
}
|
|
1412
1418
|
}
|
|
1413
|
-
if (interfaceExtensions?.[fieldName]) {
|
|
1414
|
-
interfaceExtensionFields.push(selection);
|
|
1415
|
-
} else {
|
|
1416
|
-
newSelections.add(selection);
|
|
1417
|
-
}
|
|
1418
1419
|
}
|
|
1419
1420
|
}
|
|
1420
1421
|
if (reversePossibleTypesMap2[parentType.name]) {
|
|
1421
|
-
newSelections
|
|
1422
|
+
addSelectionNodeToSelections(newSelections, {
|
|
1422
1423
|
kind: graphql.Kind.FIELD,
|
|
1423
1424
|
name: {
|
|
1424
1425
|
kind: graphql.Kind.NAME,
|
|
@@ -1430,7 +1431,8 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1430
1431
|
const possibleTypes = possibleTypesMap[parentType.name];
|
|
1431
1432
|
if (possibleTypes != null) {
|
|
1432
1433
|
for (const possibleType of possibleTypes) {
|
|
1433
|
-
|
|
1434
|
+
addSelectionNodeToSelections(
|
|
1435
|
+
newSelections,
|
|
1434
1436
|
generateInlineFragment(possibleType, {
|
|
1435
1437
|
kind: graphql.Kind.SELECTION_SET,
|
|
1436
1438
|
selections: interfaceExtensionFields
|
|
@@ -1446,6 +1448,62 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1446
1448
|
}
|
|
1447
1449
|
return node;
|
|
1448
1450
|
}
|
|
1451
|
+
function isFieldNodeSatisfiedBySelections(fieldNode, existing) {
|
|
1452
|
+
for (const existingSelection of existing) {
|
|
1453
|
+
if (existingSelection.kind === graphql.Kind.FIELD && existingSelection.name.value === fieldNode.name.value && existingSelection.alias?.value === fieldNode.alias?.value) {
|
|
1454
|
+
if (fieldNode.selectionSet && !existingSelection.selectionSet) {
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1457
|
+
if (fieldNode.selectionSet && existingSelection.selectionSet) {
|
|
1458
|
+
const satisfied = isSelectionSetSatisfied({
|
|
1459
|
+
incoming: fieldNode.selectionSet,
|
|
1460
|
+
existing: existingSelection.selectionSet.selections
|
|
1461
|
+
});
|
|
1462
|
+
if (!satisfied) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
function isSelectionSetSatisfied({
|
|
1472
|
+
incoming,
|
|
1473
|
+
existing
|
|
1474
|
+
}) {
|
|
1475
|
+
for (const incomingSelection of incoming.selections) {
|
|
1476
|
+
if (incomingSelection.kind === graphql.Kind.FIELD) {
|
|
1477
|
+
const existingField = existing.find((selection) => {
|
|
1478
|
+
return selection.kind === graphql.Kind.FIELD && selection.name.value === incomingSelection.name.value && selection.alias?.value === incomingSelection.alias?.value;
|
|
1479
|
+
});
|
|
1480
|
+
if (!existingField) {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
if (incomingSelection.selectionSet && !existingField.selectionSet) {
|
|
1484
|
+
return false;
|
|
1485
|
+
}
|
|
1486
|
+
if (incomingSelection.selectionSet && existingField.selectionSet) {
|
|
1487
|
+
const satisfied = isSelectionSetSatisfied({
|
|
1488
|
+
incoming: incomingSelection.selectionSet,
|
|
1489
|
+
existing: existingField.selectionSet.selections
|
|
1490
|
+
});
|
|
1491
|
+
if (!satisfied) {
|
|
1492
|
+
return false;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
} else {
|
|
1496
|
+
return false;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return true;
|
|
1500
|
+
}
|
|
1501
|
+
function addSelectionNodeToSelections(selections, selectionNode) {
|
|
1502
|
+
if (selectionNode.kind === graphql.Kind.FIELD && isFieldNodeSatisfiedBySelections(selectionNode, selections)) {
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
selections.add(selectionNode);
|
|
1506
|
+
}
|
|
1449
1507
|
function addDependenciesNestedly(fieldNode, seenFieldNames, fieldNodesByField, newSelections) {
|
|
1450
1508
|
if (seenFieldNames.has(fieldNode.name.value)) {
|
|
1451
1509
|
return;
|
|
@@ -1454,7 +1512,7 @@ function addDependenciesNestedly(fieldNode, seenFieldNames, fieldNodesByField, n
|
|
|
1454
1512
|
const fieldNodes = fieldNodesByField[fieldNode.name.value];
|
|
1455
1513
|
if (fieldNodes != null) {
|
|
1456
1514
|
for (const nestedFieldNode of fieldNodes) {
|
|
1457
|
-
newSelections
|
|
1515
|
+
addSelectionNodeToSelections(newSelections, nestedFieldNode);
|
|
1458
1516
|
addDependenciesNestedly(
|
|
1459
1517
|
nestedFieldNode,
|
|
1460
1518
|
seenFieldNames,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutionRequest, ExecutionResult, Executor, Maybe, GraphQLResolveInfo as GraphQLResolveInfo$1 } from '@graphql-tools/utils';
|
|
2
2
|
export { createDeferred } from '@graphql-tools/utils';
|
|
3
3
|
import * as graphql from 'graphql';
|
|
4
|
-
import { GraphQLSchema, OperationTypeNode,
|
|
4
|
+
import { GraphQLSchema, OperationTypeNode, GraphQLResolveInfo, GraphQLOutputType, GraphQLError, SelectionSetNode, GraphQLFieldResolver, FragmentDefinitionNode, FieldNode, GraphQLNamedType, GraphQLObjectType, GraphQLField, GraphQLInterfaceType, SelectionNode, GraphQLNamedOutputType, TypeInfo, GraphQLType } from 'graphql';
|
|
5
5
|
import DataLoader from 'dataloader';
|
|
6
6
|
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
7
7
|
export { executorFromSchema as createDefaultExecutor } from '@graphql-tools/executor';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExecutionRequest, ExecutionResult, Executor, Maybe, GraphQLResolveInfo as GraphQLResolveInfo$1 } from '@graphql-tools/utils';
|
|
2
2
|
export { createDeferred } from '@graphql-tools/utils';
|
|
3
3
|
import * as graphql from 'graphql';
|
|
4
|
-
import { GraphQLSchema, OperationTypeNode,
|
|
4
|
+
import { GraphQLSchema, OperationTypeNode, GraphQLResolveInfo, GraphQLOutputType, GraphQLError, SelectionSetNode, GraphQLFieldResolver, FragmentDefinitionNode, FieldNode, GraphQLNamedType, GraphQLObjectType, GraphQLField, GraphQLInterfaceType, SelectionNode, GraphQLNamedOutputType, TypeInfo, GraphQLType } from 'graphql';
|
|
5
5
|
import DataLoader from 'dataloader';
|
|
6
6
|
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
7
7
|
export { executorFromSchema as createDefaultExecutor } from '@graphql-tools/executor';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { memoize2, memoize1,
|
|
1
|
+
import { memoize2, memoize1, collectFields, relocatedError, mergeDeep, promiseReduce, pathToArray, getResponseKeyFromInfo, memoize3, getDefinedRootType, createGraphQLError, implementsAbstractType, getRootTypeNames, astFromArg, astFromValueUntyped, asArray, isAsyncIterable, getOperationASTFromRequest } from '@graphql-tools/utils';
|
|
2
2
|
export { createDeferred } from '@graphql-tools/utils';
|
|
3
3
|
import { GraphQLError, locatedError, isAbstractType, getNullableType, isLeafType, isCompositeType, isListType, responsePathAsArray, Kind, TypeInfo, versionInfo, visit, visitWithTypeInfo, isNullableType, isUnionType, getNamedType, isObjectType, isInterfaceType, isNonNullType, isInputObjectType, defaultFieldResolver, isSchema, validate } from 'graphql';
|
|
4
4
|
import { handleMaybePromise, isPromise, createDeferredPromise, mapAsyncIterator } from '@whatwg-node/promise-helpers';
|
|
@@ -1283,7 +1283,7 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1283
1283
|
const fieldNodes = fieldNodesByType[parentTypeName];
|
|
1284
1284
|
if (fieldNodes) {
|
|
1285
1285
|
for (const fieldNode of fieldNodes) {
|
|
1286
|
-
newSelections
|
|
1286
|
+
addSelectionNodeToSelections(newSelections, fieldNode);
|
|
1287
1287
|
}
|
|
1288
1288
|
}
|
|
1289
1289
|
const interfaceExtensions = interfaceExtensionsMap[parentType.name];
|
|
@@ -1300,7 +1300,7 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1300
1300
|
);
|
|
1301
1301
|
const extraPossibleTypes = getExtraPossibleTypes2(typeName);
|
|
1302
1302
|
for (const extraPossibleTypeName of extraPossibleTypes) {
|
|
1303
|
-
newSelections
|
|
1303
|
+
addSelectionNodeToSelections(newSelections, {
|
|
1304
1304
|
...selection,
|
|
1305
1305
|
typeCondition: {
|
|
1306
1306
|
kind: Kind.NAMED_TYPE,
|
|
@@ -1319,13 +1319,13 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1319
1319
|
const fieldName = subSelection.name.value;
|
|
1320
1320
|
const field = fieldMap[fieldName];
|
|
1321
1321
|
if (!field) {
|
|
1322
|
-
newSelections
|
|
1322
|
+
addSelectionNodeToSelections(newSelections, subSelection);
|
|
1323
1323
|
}
|
|
1324
1324
|
}
|
|
1325
1325
|
}
|
|
1326
1326
|
} else if (!typeInSubschema) {
|
|
1327
1327
|
for (const subSelection of selection.selectionSet.selections) {
|
|
1328
|
-
newSelections
|
|
1328
|
+
addSelectionNodeToSelections(newSelections, subSelection);
|
|
1329
1329
|
}
|
|
1330
1330
|
}
|
|
1331
1331
|
}
|
|
@@ -1334,10 +1334,10 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1334
1334
|
const fieldNodesForTypeName = fieldNodesByField[parentTypeName]?.["__typename"];
|
|
1335
1335
|
if (fieldNodesForTypeName) {
|
|
1336
1336
|
for (const fieldNode of fieldNodesForTypeName) {
|
|
1337
|
-
newSelections
|
|
1337
|
+
addSelectionNodeToSelections(newSelections, fieldNode);
|
|
1338
1338
|
}
|
|
1339
1339
|
}
|
|
1340
|
-
newSelections
|
|
1340
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1341
1341
|
continue;
|
|
1342
1342
|
}
|
|
1343
1343
|
for (const possibleTypeName of possibleTypes) {
|
|
@@ -1347,7 +1347,8 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1347
1347
|
parentType,
|
|
1348
1348
|
maybePossibleType
|
|
1349
1349
|
)) {
|
|
1350
|
-
|
|
1350
|
+
addSelectionNodeToSelections(
|
|
1351
|
+
newSelections,
|
|
1351
1352
|
generateInlineFragment(
|
|
1352
1353
|
possibleTypeName,
|
|
1353
1354
|
selection.selectionSet
|
|
@@ -1356,22 +1357,22 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1356
1357
|
}
|
|
1357
1358
|
}
|
|
1358
1359
|
if (possibleTypes.length === 0) {
|
|
1359
|
-
newSelections
|
|
1360
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1360
1361
|
}
|
|
1361
1362
|
} else {
|
|
1362
|
-
newSelections
|
|
1363
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1363
1364
|
}
|
|
1364
1365
|
} else if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
|
1365
1366
|
const fragmentName = selection.name.value;
|
|
1366
1367
|
if (!fragmentReplacements[fragmentName]) {
|
|
1367
|
-
newSelections
|
|
1368
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1368
1369
|
continue;
|
|
1369
1370
|
}
|
|
1370
1371
|
for (const replacement of fragmentReplacements[fragmentName]) {
|
|
1371
1372
|
const typeName = replacement.typeName;
|
|
1372
1373
|
const maybeReplacementType = transformedSchema.getType(typeName);
|
|
1373
1374
|
if (maybeReplacementType != null && implementsAbstractType(transformedSchema, parentType, maybeType)) {
|
|
1374
|
-
newSelections
|
|
1375
|
+
addSelectionNodeToSelections(newSelections, {
|
|
1375
1376
|
kind: Kind.FRAGMENT_SPREAD,
|
|
1376
1377
|
name: {
|
|
1377
1378
|
kind: Kind.NAME,
|
|
@@ -1382,11 +1383,16 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1382
1383
|
}
|
|
1383
1384
|
} else {
|
|
1384
1385
|
const fieldName = selection.name.value;
|
|
1386
|
+
if (interfaceExtensions?.[fieldName]) {
|
|
1387
|
+
interfaceExtensionFields.push(selection);
|
|
1388
|
+
} else {
|
|
1389
|
+
addSelectionNodeToSelections(newSelections, selection);
|
|
1390
|
+
}
|
|
1385
1391
|
if (isAbstractType(parentType)) {
|
|
1386
1392
|
const fieldNodesForTypeName = fieldNodesByField[parentTypeName]?.["__typename"];
|
|
1387
1393
|
if (fieldNodesForTypeName) {
|
|
1388
1394
|
for (const fieldNode of fieldNodesForTypeName) {
|
|
1389
|
-
newSelections
|
|
1395
|
+
addSelectionNodeToSelections(newSelections, fieldNode);
|
|
1390
1396
|
}
|
|
1391
1397
|
}
|
|
1392
1398
|
}
|
|
@@ -1405,20 +1411,15 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1405
1411
|
const selectionSet = selectionSetFn(selection);
|
|
1406
1412
|
if (selectionSet != null) {
|
|
1407
1413
|
for (const selection2 of selectionSet.selections) {
|
|
1408
|
-
newSelections
|
|
1414
|
+
addSelectionNodeToSelections(newSelections, selection2);
|
|
1409
1415
|
}
|
|
1410
1416
|
}
|
|
1411
1417
|
}
|
|
1412
1418
|
}
|
|
1413
|
-
if (interfaceExtensions?.[fieldName]) {
|
|
1414
|
-
interfaceExtensionFields.push(selection);
|
|
1415
|
-
} else {
|
|
1416
|
-
newSelections.add(selection);
|
|
1417
|
-
}
|
|
1418
1419
|
}
|
|
1419
1420
|
}
|
|
1420
1421
|
if (reversePossibleTypesMap2[parentType.name]) {
|
|
1421
|
-
newSelections
|
|
1422
|
+
addSelectionNodeToSelections(newSelections, {
|
|
1422
1423
|
kind: Kind.FIELD,
|
|
1423
1424
|
name: {
|
|
1424
1425
|
kind: Kind.NAME,
|
|
@@ -1430,7 +1431,8 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1430
1431
|
const possibleTypes = possibleTypesMap[parentType.name];
|
|
1431
1432
|
if (possibleTypes != null) {
|
|
1432
1433
|
for (const possibleType of possibleTypes) {
|
|
1433
|
-
|
|
1434
|
+
addSelectionNodeToSelections(
|
|
1435
|
+
newSelections,
|
|
1434
1436
|
generateInlineFragment(possibleType, {
|
|
1435
1437
|
kind: Kind.SELECTION_SET,
|
|
1436
1438
|
selections: interfaceExtensionFields
|
|
@@ -1446,6 +1448,62 @@ function visitSelectionSet(node, fragmentReplacements, transformedSchema, typeIn
|
|
|
1446
1448
|
}
|
|
1447
1449
|
return node;
|
|
1448
1450
|
}
|
|
1451
|
+
function isFieldNodeSatisfiedBySelections(fieldNode, existing) {
|
|
1452
|
+
for (const existingSelection of existing) {
|
|
1453
|
+
if (existingSelection.kind === Kind.FIELD && existingSelection.name.value === fieldNode.name.value && existingSelection.alias?.value === fieldNode.alias?.value) {
|
|
1454
|
+
if (fieldNode.selectionSet && !existingSelection.selectionSet) {
|
|
1455
|
+
return false;
|
|
1456
|
+
}
|
|
1457
|
+
if (fieldNode.selectionSet && existingSelection.selectionSet) {
|
|
1458
|
+
const satisfied = isSelectionSetSatisfied({
|
|
1459
|
+
incoming: fieldNode.selectionSet,
|
|
1460
|
+
existing: existingSelection.selectionSet.selections
|
|
1461
|
+
});
|
|
1462
|
+
if (!satisfied) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
function isSelectionSetSatisfied({
|
|
1472
|
+
incoming,
|
|
1473
|
+
existing
|
|
1474
|
+
}) {
|
|
1475
|
+
for (const incomingSelection of incoming.selections) {
|
|
1476
|
+
if (incomingSelection.kind === Kind.FIELD) {
|
|
1477
|
+
const existingField = existing.find((selection) => {
|
|
1478
|
+
return selection.kind === Kind.FIELD && selection.name.value === incomingSelection.name.value && selection.alias?.value === incomingSelection.alias?.value;
|
|
1479
|
+
});
|
|
1480
|
+
if (!existingField) {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
if (incomingSelection.selectionSet && !existingField.selectionSet) {
|
|
1484
|
+
return false;
|
|
1485
|
+
}
|
|
1486
|
+
if (incomingSelection.selectionSet && existingField.selectionSet) {
|
|
1487
|
+
const satisfied = isSelectionSetSatisfied({
|
|
1488
|
+
incoming: incomingSelection.selectionSet,
|
|
1489
|
+
existing: existingField.selectionSet.selections
|
|
1490
|
+
});
|
|
1491
|
+
if (!satisfied) {
|
|
1492
|
+
return false;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
} else {
|
|
1496
|
+
return false;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
return true;
|
|
1500
|
+
}
|
|
1501
|
+
function addSelectionNodeToSelections(selections, selectionNode) {
|
|
1502
|
+
if (selectionNode.kind === Kind.FIELD && isFieldNodeSatisfiedBySelections(selectionNode, selections)) {
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
selections.add(selectionNode);
|
|
1506
|
+
}
|
|
1449
1507
|
function addDependenciesNestedly(fieldNode, seenFieldNames, fieldNodesByField, newSelections) {
|
|
1450
1508
|
if (seenFieldNames.has(fieldNode.name.value)) {
|
|
1451
1509
|
return;
|
|
@@ -1454,7 +1512,7 @@ function addDependenciesNestedly(fieldNode, seenFieldNames, fieldNodesByField, n
|
|
|
1454
1512
|
const fieldNodes = fieldNodesByField[fieldNode.name.value];
|
|
1455
1513
|
if (fieldNodes != null) {
|
|
1456
1514
|
for (const nestedFieldNode of fieldNodes) {
|
|
1457
|
-
newSelections
|
|
1515
|
+
addSelectionNodeToSelections(newSelections, nestedFieldNode);
|
|
1458
1516
|
addDependenciesNestedly(
|
|
1459
1517
|
nestedFieldNode,
|
|
1460
1518
|
seenFieldNames,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.5-alpha-6bcca2bc60aea3f017e008bd95b91f282608f123",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
6
6
|
"repository": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"tslib": "^2.8.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/lodash": "4.17.
|
|
51
|
+
"@types/lodash": "4.17.23",
|
|
52
52
|
"graphql": "^16.12.0",
|
|
53
|
-
"pkgroll": "2.
|
|
53
|
+
"pkgroll": "2.23.0"
|
|
54
54
|
},
|
|
55
55
|
"sideEffects": false
|
|
56
56
|
}
|