@wundergraph/composition 0.22.1 → 0.23.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/dist/errors/errors.d.ts +9 -4
- package/dist/errors/errors.js +45 -16
- package/dist/errors/errors.js.map +1 -1
- package/dist/federation/federation-factory.d.ts +43 -23
- package/dist/federation/federation-factory.js +1011 -319
- package/dist/federation/federation-factory.js.map +1 -1
- package/dist/federation/utils.d.ts +25 -1
- package/dist/federation/utils.js +17 -0
- package/dist/federation/utils.js.map +1 -1
- package/dist/federation/walkers.js +1 -1
- package/dist/federation/walkers.js.map +1 -1
- package/dist/normalization/normalization-factory.d.ts +2 -1
- package/dist/normalization/normalization-factory.js +37 -11
- package/dist/normalization/normalization-factory.js.map +1 -1
- package/dist/normalization/utils.js +11 -2
- package/dist/normalization/utils.js.map +1 -1
- package/dist/schema-building/type-definition-data.d.ts +3 -1
- package/dist/schema-building/type-extension-data.d.ts +1 -0
- package/dist/schema-building/utils.d.ts +11 -7
- package/dist/schema-building/utils.js +70 -334
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/string-constants.d.ts +1 -0
- package/dist/utils/string-constants.js +2 -1
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js.map +1 -1
- package/package.json +4 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MergeMethod = exports.isFieldExternalInAllMutualSubgraphs = exports.isShareabilityOfAllFieldInstancesValid = exports.addValidPersistedDirectiveDefinitionNodeByData = exports.getValidFieldArgumentNodes = exports.getNodeWithPersistedDirectivesByInputValueData = exports.getClientSchemaFieldNodeByFieldData = exports.getNodeWithPersistedDirectivesByFieldData = exports.getNodeForRouterSchemaByData = exports.getClientPersistedDirectiveNodes = exports.pushAuthorizationDirectives = exports.upsertPersistedDirectivesData = exports.extractPersistedDirectives = exports.setLongestDescription = exports.removeInheritableDirectivesFromParentWithFieldsData = exports.getUnionNodeByData = exports.getSchemaNodeByData = exports.getScalarNodeByData = exports.getParentWithFieldsNodeByData = exports.getInputObjectNodeByData = exports.getEnumNodeByData = exports.extractImplementedInterfaceTypeNames = exports.convertKindForExtension = exports.getRenamedRootTypeName = exports.isTypeNameRootType = exports.addUnionExtensionDataByNode = exports.addUnionDefinitionDataByNode = exports.extractUniqueUnionMembers = exports.addScalarExtensionDataByNode = exports.addScalarDefinitionDataByNode = exports.setMutualExecutableLocations = exports.addPersistedDirectiveDefinitionDataByNode = exports.addObjectDefinitionDataByNode = exports.addInterfaceDefinitionDataByNode = exports.addInputValueDataByNode = exports.addInputObjectExtensionDataByNode = exports.addInputObjectDefinitionDataByNode = exports.addExtensionWithFieldsDataByNode = exports.addFieldDataByNode = exports.addInheritedDirectivesToFieldData = exports.addEnumValueDataByNode = exports.addEnumExtensionDataByNode = exports.addEnumDefinitionDataByNode = exports.compareAndValidateInputValueDefaultValues = exports.isTypeRequired = exports.extractArguments = exports.extractDirectives = exports.getDirectiveValidationErrors = exports.getDefinedArgumentsForDirective = exports.isNodeExternalOrShareable = void 0;
|
|
4
|
+
exports.isNodeDataInaccessible = exports.isTypeValidImplementation = void 0;
|
|
4
5
|
const graphql_1 = require("graphql");
|
|
5
6
|
const ast_1 = require("./ast");
|
|
6
7
|
const utils_1 = require("../ast/utils");
|
|
7
8
|
const errors_1 = require("../errors/errors");
|
|
8
9
|
const string_constants_1 = require("../utils/string-constants");
|
|
9
|
-
const type_merging_1 = require("./type-merging");
|
|
10
10
|
const utils_2 = require("../normalization/utils");
|
|
11
11
|
const utils_3 = require("../utils/utils");
|
|
12
12
|
const constants_1 = require("../utils/constants");
|
|
@@ -226,6 +226,7 @@ function compareAndValidateInputValueDefaultValues(existingData, incomingData, e
|
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
+
exports.compareAndValidateInputValueDefaultValues = compareAndValidateInputValueDefaultValues;
|
|
229
230
|
function addEnumDefinitionDataByNode(parentDefinitionDataByTypeName, node, directivesByDirectiveName) {
|
|
230
231
|
const name = node.name.value;
|
|
231
232
|
parentDefinitionDataByTypeName.set(name, {
|
|
@@ -311,11 +312,13 @@ function addExtensionWithFieldsDataByNode(parentExtensionDataByTypeName, node, e
|
|
|
311
312
|
});
|
|
312
313
|
return;
|
|
313
314
|
default:
|
|
315
|
+
const directivesByDirectiveName = extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name);
|
|
314
316
|
parentExtensionDataByTypeName.set(name, {
|
|
315
|
-
directivesByDirectiveName
|
|
317
|
+
directivesByDirectiveName,
|
|
316
318
|
fieldDataByFieldName: new Map(),
|
|
317
319
|
implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
|
|
318
320
|
isEntity,
|
|
321
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
319
322
|
isRootType,
|
|
320
323
|
kind,
|
|
321
324
|
name,
|
|
@@ -329,9 +332,11 @@ function addExtensionWithFieldsDataByNode(parentExtensionDataByTypeName, node, e
|
|
|
329
332
|
exports.addExtensionWithFieldsDataByNode = addExtensionWithFieldsDataByNode;
|
|
330
333
|
function addInputObjectDefinitionDataByNode(parentDefinitionDataByTypeName, node, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, subgraphName, errors) {
|
|
331
334
|
const name = node.name.value;
|
|
335
|
+
const directivesByDirectiveName = extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name);
|
|
332
336
|
parentDefinitionDataByTypeName.set(name, {
|
|
333
|
-
directivesByDirectiveName
|
|
337
|
+
directivesByDirectiveName,
|
|
334
338
|
inputValueDataByValueName: new Map(),
|
|
339
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
335
340
|
kind: node.kind,
|
|
336
341
|
node: (0, ast_1.getMutableInputObjectNode)(node),
|
|
337
342
|
persistedDirectivesData: newPersistedDirectivesData(),
|
|
@@ -377,10 +382,12 @@ function addInputValueDataByNode(inputValueDataByValueName, node, directiveDefin
|
|
|
377
382
|
exports.addInputValueDataByNode = addInputValueDataByNode;
|
|
378
383
|
function addInterfaceDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, subgraphName) {
|
|
379
384
|
const name = node.name.value;
|
|
385
|
+
const directivesByDirectiveName = extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name);
|
|
380
386
|
parentDefinitionDataByTypeName.set(name, {
|
|
381
|
-
directivesByDirectiveName
|
|
387
|
+
directivesByDirectiveName,
|
|
382
388
|
fieldDataByFieldName: new Map(),
|
|
383
389
|
isEntity,
|
|
390
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
384
391
|
implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
|
|
385
392
|
kind: node.kind,
|
|
386
393
|
node: (0, ast_1.getMutableInterfaceNode)(node),
|
|
@@ -393,10 +400,12 @@ function addInterfaceDefinitionDataByNode(parentDefinitionDataByTypeName, node,
|
|
|
393
400
|
exports.addInterfaceDefinitionDataByNode = addInterfaceDefinitionDataByNode;
|
|
394
401
|
function addObjectDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, isRootType, subgraphName, renamedTypeName) {
|
|
395
402
|
const name = node.name.value;
|
|
403
|
+
const directivesByDirectiveName = extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name);
|
|
396
404
|
parentDefinitionDataByTypeName.set(name, {
|
|
397
|
-
directivesByDirectiveName
|
|
405
|
+
directivesByDirectiveName,
|
|
398
406
|
fieldDataByFieldName: new Map(),
|
|
399
407
|
isEntity,
|
|
408
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
400
409
|
isRootType,
|
|
401
410
|
implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
|
|
402
411
|
kind: node.kind,
|
|
@@ -435,49 +444,7 @@ function setMutualExecutableLocations(persistedDirectiveDefinitionData, incoming
|
|
|
435
444
|
}
|
|
436
445
|
persistedDirectiveDefinitionData.executableLocations = mutualExecutableLocations;
|
|
437
446
|
}
|
|
438
|
-
|
|
439
|
-
const name = incomingData.name;
|
|
440
|
-
const existingData = persistedDirectiveDefinitionDataByDirectiveName.get(name);
|
|
441
|
-
if (!existingData) {
|
|
442
|
-
// The executable directive must be defined in all subgraphs to be persisted.
|
|
443
|
-
if (subgraphNumber > 1) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
const argumentDataByArgumentName = new Map();
|
|
447
|
-
for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
|
|
448
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
449
|
-
upsertInputValueData(argumentDataByArgumentName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
450
|
-
}
|
|
451
|
-
persistedDirectiveDefinitionDataByDirectiveName.set(name, {
|
|
452
|
-
argumentDataByArgumentName,
|
|
453
|
-
executableLocations: new Set(incomingData.executableLocations),
|
|
454
|
-
name,
|
|
455
|
-
repeatable: incomingData.repeatable,
|
|
456
|
-
subgraphNames: new Set(incomingData.subgraphNames),
|
|
457
|
-
description: incomingData.description,
|
|
458
|
-
});
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
// If the executable directive has not been defined in at least one graph, the definition should not be persisted
|
|
462
|
-
if (existingData.subgraphNames.size + 1 !== subgraphNumber) {
|
|
463
|
-
persistedDirectiveDefinitionDataByDirectiveName.delete(name);
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
setMutualExecutableLocations(existingData, incomingData.executableLocations);
|
|
467
|
-
// If there are no mutually defined executable locations, the definition should not be persisted
|
|
468
|
-
if (existingData.executableLocations.size < 1) {
|
|
469
|
-
persistedDirectiveDefinitionDataByDirectiveName.delete(name);
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
|
|
473
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
474
|
-
upsertInputValueData(existingData.argumentDataByArgumentName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
475
|
-
}
|
|
476
|
-
setLongestDescription(existingData, incomingData);
|
|
477
|
-
existingData.repeatable &&= incomingData.repeatable;
|
|
478
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
|
|
479
|
-
}
|
|
480
|
-
exports.upsertPersistedDirectiveDefinitionData = upsertPersistedDirectiveDefinitionData;
|
|
447
|
+
exports.setMutualExecutableLocations = setMutualExecutableLocations;
|
|
481
448
|
function addScalarDefinitionDataByNode(parentDefinitionDataByTypeName, node, directivesByDirectiveName) {
|
|
482
449
|
const name = node.name.value;
|
|
483
450
|
parentDefinitionDataByTypeName.set(name, {
|
|
@@ -765,6 +732,7 @@ function setLongestDescription(existingData, incomingData) {
|
|
|
765
732
|
existingData.description = { ...incomingData.description, block: true };
|
|
766
733
|
}
|
|
767
734
|
}
|
|
735
|
+
exports.setLongestDescription = setLongestDescription;
|
|
768
736
|
function upsertDeprecatedDirective(persistedDirectivesData, incomingDirectiveNode) {
|
|
769
737
|
if (!incomingDirectiveNode.arguments?.length) {
|
|
770
738
|
return;
|
|
@@ -801,250 +769,15 @@ function extractPersistedDirectives(persistedDirectivesData, directivesByDirecti
|
|
|
801
769
|
persistedDirectivesData.directives.set(directiveName, directiveNodes);
|
|
802
770
|
continue;
|
|
803
771
|
}
|
|
772
|
+
// Only add one instance of the @inaccessible directive
|
|
773
|
+
if (directiveName === string_constants_1.INACCESSIBLE) {
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
804
776
|
existingDirectives.push(...directiveNodes);
|
|
805
777
|
}
|
|
806
778
|
return persistedDirectivesData;
|
|
807
779
|
}
|
|
808
|
-
|
|
809
|
-
const existingData = enumValueDataByValueName.get(incomingData.name);
|
|
810
|
-
extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
811
|
-
if (!existingData) {
|
|
812
|
-
incomingData.node = {
|
|
813
|
-
directives: [],
|
|
814
|
-
kind: incomingData.node.kind,
|
|
815
|
-
name: (0, utils_1.stringToNameNode)(incomingData.name),
|
|
816
|
-
};
|
|
817
|
-
enumValueDataByValueName.set(incomingData.name, incomingData);
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
existingData.appearances += 1;
|
|
821
|
-
setLongestDescription(existingData, incomingData);
|
|
822
|
-
}
|
|
823
|
-
function upsertFieldData(fieldDataByFieldName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors) {
|
|
824
|
-
namedOutputTypeNames.add(incomingData.namedTypeName);
|
|
825
|
-
const existingData = fieldDataByFieldName.get(incomingData.name);
|
|
826
|
-
extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
827
|
-
if (!existingData) {
|
|
828
|
-
fieldDataByFieldName.set(incomingData.name, incomingData);
|
|
829
|
-
incomingData.node = {
|
|
830
|
-
arguments: [],
|
|
831
|
-
directives: [],
|
|
832
|
-
kind: incomingData.node.kind,
|
|
833
|
-
name: (0, utils_1.stringToNameNode)(incomingData.name),
|
|
834
|
-
type: incomingData.type,
|
|
835
|
-
};
|
|
836
|
-
for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
|
|
837
|
-
inputValueData.node = {
|
|
838
|
-
directives: [],
|
|
839
|
-
kind: inputValueData.node.kind,
|
|
840
|
-
name: (0, utils_1.stringToNameNode)(inputValueData.name),
|
|
841
|
-
type: inputValueData.type,
|
|
842
|
-
};
|
|
843
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
844
|
-
extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
845
|
-
}
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
const fieldPath = `${existingData.renamedParentTypeName}.${existingData.name}`;
|
|
849
|
-
const { typeErrors, typeNode } = (0, type_merging_1.getLeastRestrictiveMergedTypeNode)(existingData.type, incomingData.type, fieldPath, errors);
|
|
850
|
-
if (typeNode) {
|
|
851
|
-
existingData.type = typeNode;
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
if (!typeErrors || typeErrors.length < 2) {
|
|
855
|
-
throw (0, errors_1.fieldTypeMergeFatalError)(existingData.name);
|
|
856
|
-
}
|
|
857
|
-
errors.push((0, errors_1.incompatibleChildTypesError)(fieldPath, typeErrors[0], typeErrors[1]));
|
|
858
|
-
}
|
|
859
|
-
for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
|
|
860
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
861
|
-
upsertInputValueData(existingData.argumentDataByArgumentName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
862
|
-
}
|
|
863
|
-
setLongestDescription(existingData, incomingData);
|
|
864
|
-
existingData.isInaccessible ||= incomingData.isInaccessible;
|
|
865
|
-
(0, utils_3.addMapEntries)(incomingData.isExternalBySubgraphName, existingData.isExternalBySubgraphName);
|
|
866
|
-
(0, utils_3.addMapEntries)(incomingData.isShareableBySubgraphName, existingData.isShareableBySubgraphName);
|
|
867
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
|
|
868
|
-
}
|
|
869
|
-
function upsertInputValueData(inputValueDataByValueName, incomingData, persistedDirectiveDefinitionByDirectiveName, errors) {
|
|
870
|
-
const existingData = inputValueDataByValueName.get(incomingData.name);
|
|
871
|
-
extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
872
|
-
if (!existingData) {
|
|
873
|
-
incomingData.node = {
|
|
874
|
-
directives: [],
|
|
875
|
-
kind: incomingData.node.kind,
|
|
876
|
-
name: (0, utils_1.stringToNameNode)(incomingData.name),
|
|
877
|
-
type: incomingData.type,
|
|
878
|
-
};
|
|
879
|
-
inputValueDataByValueName.set(incomingData.name, incomingData);
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
setLongestDescription(existingData, incomingData);
|
|
883
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.requiredSubgraphNames, existingData.requiredSubgraphNames);
|
|
884
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
|
|
885
|
-
// TODO refactor type merging
|
|
886
|
-
const { typeErrors, typeNode } = (0, type_merging_1.getMostRestrictiveMergedTypeNode)(existingData.type, incomingData.type, existingData.originalPath, errors);
|
|
887
|
-
if (typeNode) {
|
|
888
|
-
existingData.type = typeNode;
|
|
889
|
-
}
|
|
890
|
-
else {
|
|
891
|
-
if (!typeErrors || typeErrors.length < 2) {
|
|
892
|
-
throw (0, errors_1.fieldTypeMergeFatalError)(existingData.name);
|
|
893
|
-
}
|
|
894
|
-
existingData.isArgument
|
|
895
|
-
? errors.push((0, errors_1.incompatibleArgumentTypesError)(existingData.name, existingData.renamedPath, typeErrors[0], typeErrors[1]))
|
|
896
|
-
: errors.push((0, errors_1.incompatibleChildTypesError)(existingData.renamedPath, typeErrors[0], typeErrors[1]));
|
|
897
|
-
}
|
|
898
|
-
compareAndValidateInputValueDefaultValues(existingData, incomingData, errors);
|
|
899
|
-
}
|
|
900
|
-
function upsertParentDefinitionData(parentDefinitionDataByTypeName, incomingData, persistedDirectiveDefinitionByDirectiveName, entityInterfaceFederationDataByTypeName, namedOutputTypeNames, namedInputValueTypeNames, subgraphName, errors) {
|
|
901
|
-
const entityInterfaceData = entityInterfaceFederationDataByTypeName.get(incomingData.name);
|
|
902
|
-
const existingData = parentDefinitionDataByTypeName.get(incomingData.name);
|
|
903
|
-
extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
904
|
-
if (!existingData) {
|
|
905
|
-
if (entityInterfaceData && entityInterfaceData.interfaceObjectSubgraphs.has(subgraphName)) {
|
|
906
|
-
incomingData.kind = graphql_1.Kind.INTERFACE_TYPE_DEFINITION;
|
|
907
|
-
}
|
|
908
|
-
incomingData.node = {
|
|
909
|
-
kind: incomingData.kind,
|
|
910
|
-
name: (0, utils_1.stringToNameNode)(incomingData.name),
|
|
911
|
-
};
|
|
912
|
-
parentDefinitionDataByTypeName.set(incomingData.name, incomingData);
|
|
913
|
-
switch (incomingData.kind) {
|
|
914
|
-
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
|
|
915
|
-
for (const enumValueData of incomingData.enumValueDataByValueName.values()) {
|
|
916
|
-
enumValueData.node = {
|
|
917
|
-
directives: [],
|
|
918
|
-
kind: enumValueData.node.kind,
|
|
919
|
-
name: (0, utils_1.stringToNameNode)(enumValueData.name),
|
|
920
|
-
};
|
|
921
|
-
extractPersistedDirectives(enumValueData.persistedDirectivesData, enumValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
922
|
-
}
|
|
923
|
-
return;
|
|
924
|
-
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
925
|
-
for (const inputValueData of incomingData.inputValueDataByValueName.values()) {
|
|
926
|
-
inputValueData.node = {
|
|
927
|
-
directives: [],
|
|
928
|
-
kind: inputValueData.node.kind,
|
|
929
|
-
name: (0, utils_1.stringToNameNode)(inputValueData.name),
|
|
930
|
-
type: inputValueData.type,
|
|
931
|
-
};
|
|
932
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
933
|
-
extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
934
|
-
}
|
|
935
|
-
return;
|
|
936
|
-
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
937
|
-
// intentional fallthrough
|
|
938
|
-
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
939
|
-
for (const fieldData of incomingData.fieldDataByFieldName.values()) {
|
|
940
|
-
fieldData.node = {
|
|
941
|
-
arguments: [],
|
|
942
|
-
directives: [],
|
|
943
|
-
kind: fieldData.node.kind,
|
|
944
|
-
name: (0, utils_1.stringToNameNode)(fieldData.name),
|
|
945
|
-
type: fieldData.type,
|
|
946
|
-
};
|
|
947
|
-
namedOutputTypeNames.add(fieldData.namedTypeName);
|
|
948
|
-
extractPersistedDirectives(fieldData.persistedDirectivesData, fieldData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
949
|
-
for (const inputValueData of fieldData.argumentDataByArgumentName.values()) {
|
|
950
|
-
inputValueData.node = {
|
|
951
|
-
directives: [],
|
|
952
|
-
kind: inputValueData.node.kind,
|
|
953
|
-
name: (0, utils_1.stringToNameNode)(inputValueData.name),
|
|
954
|
-
type: inputValueData.type,
|
|
955
|
-
};
|
|
956
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
957
|
-
extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
return;
|
|
961
|
-
default:
|
|
962
|
-
// Scalar and Union
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
setLongestDescription(existingData, incomingData);
|
|
967
|
-
if (existingData.kind !== incomingData.kind) {
|
|
968
|
-
if (!entityInterfaceData ||
|
|
969
|
-
!entityInterfaceData.interfaceObjectSubgraphs.has(subgraphName) ||
|
|
970
|
-
existingData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION ||
|
|
971
|
-
incomingData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
972
|
-
errors.push((0, errors_1.incompatibleParentKindMergeError)(existingData.name, (0, utils_3.kindToTypeString)(existingData.kind), (0, utils_3.kindToTypeString)(incomingData.kind)));
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
switch (existingData.kind) {
|
|
977
|
-
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
|
|
978
|
-
existingData.appearances += 1;
|
|
979
|
-
for (const data of incomingData.enumValueDataByValueName.values()) {
|
|
980
|
-
upsertEnumValueData(existingData.enumValueDataByValueName, data, persistedDirectiveDefinitionByDirectiveName);
|
|
981
|
-
}
|
|
982
|
-
return;
|
|
983
|
-
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
984
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
|
|
985
|
-
for (const inputValueData of incomingData.inputValueDataByValueName.values()) {
|
|
986
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
987
|
-
upsertInputValueData(existingData.inputValueDataByValueName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
988
|
-
}
|
|
989
|
-
return;
|
|
990
|
-
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
991
|
-
// intentional fallthrough
|
|
992
|
-
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
993
|
-
const objectData = incomingData;
|
|
994
|
-
(0, utils_3.addIterableValuesToSet)(objectData.implementedInterfaceTypeNames, existingData.implementedInterfaceTypeNames);
|
|
995
|
-
(0, utils_3.addIterableValuesToSet)(objectData.subgraphNames, existingData.subgraphNames);
|
|
996
|
-
for (const fieldData of objectData.fieldDataByFieldName.values()) {
|
|
997
|
-
upsertFieldData(existingData.fieldDataByFieldName, fieldData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors);
|
|
998
|
-
}
|
|
999
|
-
return;
|
|
1000
|
-
case graphql_1.Kind.UNION_TYPE_DEFINITION:
|
|
1001
|
-
(0, utils_3.addMapEntries)(incomingData.memberByMemberTypeName, existingData.memberByMemberTypeName);
|
|
1002
|
-
return;
|
|
1003
|
-
default:
|
|
1004
|
-
// Scalar type
|
|
1005
|
-
return;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
exports.upsertParentDefinitionData = upsertParentDefinitionData;
|
|
1009
|
-
function upsertObjectExtensionData(parentExtensionDataByTypeName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors) {
|
|
1010
|
-
const existingData = parentExtensionDataByTypeName.get(incomingData.name);
|
|
1011
|
-
extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
1012
|
-
if (!existingData) {
|
|
1013
|
-
incomingData.node = {
|
|
1014
|
-
kind: incomingData.kind,
|
|
1015
|
-
name: (0, utils_1.stringToNameNode)(incomingData.name),
|
|
1016
|
-
};
|
|
1017
|
-
for (const fieldData of incomingData.fieldDataByFieldName.values()) {
|
|
1018
|
-
fieldData.node = {
|
|
1019
|
-
arguments: [],
|
|
1020
|
-
directives: [],
|
|
1021
|
-
kind: fieldData.node.kind,
|
|
1022
|
-
name: (0, utils_1.stringToNameNode)(fieldData.name),
|
|
1023
|
-
type: fieldData.type,
|
|
1024
|
-
};
|
|
1025
|
-
namedOutputTypeNames.add(fieldData.namedTypeName);
|
|
1026
|
-
extractPersistedDirectives(fieldData.persistedDirectivesData, fieldData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
1027
|
-
for (const inputValueData of fieldData.argumentDataByArgumentName.values()) {
|
|
1028
|
-
inputValueData.node = {
|
|
1029
|
-
directives: [],
|
|
1030
|
-
kind: inputValueData.node.kind,
|
|
1031
|
-
name: (0, utils_1.stringToNameNode)(inputValueData.name),
|
|
1032
|
-
type: inputValueData.type,
|
|
1033
|
-
};
|
|
1034
|
-
namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
|
|
1035
|
-
extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
parentExtensionDataByTypeName.set(incomingData.name, incomingData);
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.implementedInterfaceTypeNames, existingData.implementedInterfaceTypeNames);
|
|
1042
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
|
|
1043
|
-
for (const fieldData of incomingData.fieldDataByFieldName.values()) {
|
|
1044
|
-
upsertFieldData(existingData.fieldDataByFieldName, fieldData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
exports.upsertObjectExtensionData = upsertObjectExtensionData;
|
|
780
|
+
exports.extractPersistedDirectives = extractPersistedDirectives;
|
|
1048
781
|
function upsertPersistedDirectivesData(existingData, incomingData) {
|
|
1049
782
|
if (incomingData.isDeprecated && existingData.deprecatedReason.length < incomingData.deprecatedReason.length) {
|
|
1050
783
|
existingData.isDeprecated = true;
|
|
@@ -1065,6 +798,7 @@ function upsertPersistedDirectivesData(existingData, incomingData) {
|
|
|
1065
798
|
existingData.tags.set(tagName, tagDirectiveNode);
|
|
1066
799
|
}
|
|
1067
800
|
}
|
|
801
|
+
exports.upsertPersistedDirectivesData = upsertPersistedDirectivesData;
|
|
1068
802
|
function pushAuthorizationDirectives(fieldData, authorizationData) {
|
|
1069
803
|
if (!authorizationData) {
|
|
1070
804
|
return;
|
|
@@ -1083,45 +817,6 @@ function pushAuthorizationDirectives(fieldData, authorizationData) {
|
|
|
1083
817
|
}
|
|
1084
818
|
}
|
|
1085
819
|
exports.pushAuthorizationDirectives = pushAuthorizationDirectives;
|
|
1086
|
-
function upsertValidObjectExtensionData(parentDefinitionDataByTypeName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors, authorizationData) {
|
|
1087
|
-
const existingData = parentDefinitionDataByTypeName.get(incomingData.name);
|
|
1088
|
-
if (!existingData) {
|
|
1089
|
-
if (incomingData.isRootType) {
|
|
1090
|
-
for (const fieldData of incomingData.fieldDataByFieldName.values()) {
|
|
1091
|
-
pushAuthorizationDirectives(fieldData, authorizationData);
|
|
1092
|
-
}
|
|
1093
|
-
parentDefinitionDataByTypeName.set(incomingData.name, {
|
|
1094
|
-
directivesByDirectiveName: incomingData.directivesByDirectiveName,
|
|
1095
|
-
fieldDataByFieldName: incomingData.fieldDataByFieldName,
|
|
1096
|
-
implementedInterfaceTypeNames: incomingData.implementedInterfaceTypeNames,
|
|
1097
|
-
isRootType: true,
|
|
1098
|
-
isEntity: false,
|
|
1099
|
-
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
|
1100
|
-
name: incomingData.name,
|
|
1101
|
-
node: {
|
|
1102
|
-
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
|
1103
|
-
name: (0, utils_1.stringToNameNode)(incomingData.name),
|
|
1104
|
-
},
|
|
1105
|
-
persistedDirectivesData: incomingData.persistedDirectivesData,
|
|
1106
|
-
renamedTypeName: incomingData.renamedTypeName,
|
|
1107
|
-
subgraphNames: incomingData.subgraphNames,
|
|
1108
|
-
});
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
errors.push((0, errors_1.noBaseTypeExtensionError)(incomingData.name));
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
if (existingData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
1115
|
-
errors.push((0, errors_1.incompatibleObjectExtensionOrphanBaseTypeError)(existingData.name, (0, utils_3.kindToTypeString)(existingData.kind)));
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
upsertPersistedDirectivesData(existingData.persistedDirectivesData, incomingData.persistedDirectivesData);
|
|
1119
|
-
(0, utils_3.addIterableValuesToSet)(incomingData.implementedInterfaceTypeNames, existingData.implementedInterfaceTypeNames);
|
|
1120
|
-
for (const fieldData of incomingData.fieldDataByFieldName.values()) {
|
|
1121
|
-
upsertFieldData(existingData.fieldDataByFieldName, fieldData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors);
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
exports.upsertValidObjectExtensionData = upsertValidObjectExtensionData;
|
|
1125
820
|
function generateDeprecatedDirective(reason) {
|
|
1126
821
|
return {
|
|
1127
822
|
kind: graphql_1.Kind.DIRECTIVE,
|
|
@@ -1157,7 +852,7 @@ function getValidFlattenedPersistedDirectiveNodeArray(directivesByDirectiveName,
|
|
|
1157
852
|
}
|
|
1158
853
|
return persistedDirectiveNodes;
|
|
1159
854
|
}
|
|
1160
|
-
function
|
|
855
|
+
function getRouterPersistedDirectiveNodes(nodeData, persistedDirectiveDefinitionByDirectiveName, errors) {
|
|
1161
856
|
const persistedDirectiveNodes = [...nodeData.persistedDirectivesData.tags.values()];
|
|
1162
857
|
if (nodeData.persistedDirectivesData.isDeprecated) {
|
|
1163
858
|
persistedDirectiveNodes.push(generateDeprecatedDirective(nodeData.persistedDirectivesData.deprecatedReason));
|
|
@@ -1165,27 +860,64 @@ function getPersistedDirectiveNodes(nodeData, persistedDirectiveDefinitionByDire
|
|
|
1165
860
|
persistedDirectiveNodes.push(...getValidFlattenedPersistedDirectiveNodeArray(nodeData.persistedDirectivesData.directives, persistedDirectiveDefinitionByDirectiveName, nodeData.name, errors));
|
|
1166
861
|
return persistedDirectiveNodes;
|
|
1167
862
|
}
|
|
1168
|
-
function
|
|
863
|
+
function getClientPersistedDirectiveNodes(nodeData) {
|
|
864
|
+
const persistedDirectiveNodes = [];
|
|
865
|
+
if (nodeData.persistedDirectivesData.isDeprecated) {
|
|
866
|
+
persistedDirectiveNodes.push(generateDeprecatedDirective(nodeData.persistedDirectivesData.deprecatedReason));
|
|
867
|
+
}
|
|
868
|
+
for (const [directiveName, directiveNodes] of nodeData.persistedDirectivesData.directives) {
|
|
869
|
+
// Only include @deprecated, @authenticated, and @requiresScopes in the client schema
|
|
870
|
+
if (!string_constants_1.PERSISTED_CLIENT_DIRECTIVES.has(directiveName)) {
|
|
871
|
+
continue;
|
|
872
|
+
}
|
|
873
|
+
/* Persisted client-facing directives or all non-repeatable.
|
|
874
|
+
** The directive is validated against the definition when creating the router schema node, so it is not necessary
|
|
875
|
+
** to validate again. */
|
|
876
|
+
persistedDirectiveNodes.push(directiveNodes[0]);
|
|
877
|
+
}
|
|
878
|
+
return persistedDirectiveNodes;
|
|
879
|
+
}
|
|
880
|
+
exports.getClientPersistedDirectiveNodes = getClientPersistedDirectiveNodes;
|
|
881
|
+
function getNodeForRouterSchemaByData(data, persistedDirectiveDefinitionByDirectiveName, errors) {
|
|
1169
882
|
data.node.name = (0, utils_1.stringToNameNode)(data.name);
|
|
1170
883
|
data.node.description = data.description;
|
|
1171
|
-
data.node.directives =
|
|
884
|
+
data.node.directives = getRouterPersistedDirectiveNodes(data, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
1172
885
|
return data.node;
|
|
1173
886
|
}
|
|
1174
|
-
exports.
|
|
887
|
+
exports.getNodeForRouterSchemaByData = getNodeForRouterSchemaByData;
|
|
1175
888
|
function getNodeWithPersistedDirectivesByFieldData(fieldData, persistedDirectiveDefinitionByDirectiveName, argumentNodes, errors) {
|
|
1176
889
|
fieldData.node.arguments = argumentNodes;
|
|
1177
890
|
fieldData.node.name = (0, utils_1.stringToNameNode)(fieldData.name);
|
|
1178
891
|
fieldData.node.type = fieldData.type;
|
|
1179
892
|
fieldData.node.description = fieldData.description;
|
|
1180
|
-
fieldData.node.directives =
|
|
893
|
+
fieldData.node.directives = getRouterPersistedDirectiveNodes(fieldData, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
1181
894
|
return fieldData.node;
|
|
1182
895
|
}
|
|
1183
896
|
exports.getNodeWithPersistedDirectivesByFieldData = getNodeWithPersistedDirectivesByFieldData;
|
|
897
|
+
function getClientSchemaFieldNodeByFieldData(fieldData) {
|
|
898
|
+
const directives = getClientPersistedDirectiveNodes(fieldData);
|
|
899
|
+
const argumentNodes = [];
|
|
900
|
+
for (const inputValueData of fieldData.argumentDataByArgumentName.values()) {
|
|
901
|
+
if (isNodeDataInaccessible(inputValueData)) {
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
argumentNodes.push({
|
|
905
|
+
...inputValueData.node,
|
|
906
|
+
directives: getClientPersistedDirectiveNodes(inputValueData),
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
return {
|
|
910
|
+
...fieldData.node,
|
|
911
|
+
directives,
|
|
912
|
+
arguments: argumentNodes,
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
exports.getClientSchemaFieldNodeByFieldData = getClientSchemaFieldNodeByFieldData;
|
|
1184
916
|
function getNodeWithPersistedDirectivesByInputValueData(inputValueData, persistedDirectiveDefinitionByDirectiveName, errors) {
|
|
1185
917
|
inputValueData.node.name = (0, utils_1.stringToNameNode)(inputValueData.name);
|
|
1186
918
|
inputValueData.node.type = inputValueData.type;
|
|
1187
919
|
inputValueData.node.description = inputValueData.description;
|
|
1188
|
-
inputValueData.node.directives =
|
|
920
|
+
inputValueData.node.directives = getRouterPersistedDirectiveNodes(inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
|
|
1189
921
|
if (inputValueData.includeDefaultValue) {
|
|
1190
922
|
inputValueData.node.defaultValue = inputValueData.defaultValue;
|
|
1191
923
|
}
|
|
@@ -1347,4 +1079,8 @@ function isTypeValidImplementation(originalType, implementationType, concreteTyp
|
|
|
1347
1079
|
}
|
|
1348
1080
|
}
|
|
1349
1081
|
exports.isTypeValidImplementation = isTypeValidImplementation;
|
|
1082
|
+
function isNodeDataInaccessible(data) {
|
|
1083
|
+
return data.persistedDirectivesData.directives.has(string_constants_1.INACCESSIBLE);
|
|
1084
|
+
}
|
|
1085
|
+
exports.isNodeDataInaccessible = isNodeDataInaccessible;
|
|
1350
1086
|
//# sourceMappingURL=utils.js.map
|