@wundergraph/composition 0.48.3 → 0.48.4
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/federation/types.d.ts +3 -3
- package/dist/schema-building/types.d.ts +11 -11
- package/dist/schema-building/utils.d.ts +1 -1
- package/dist/schema-building/utils.js +17 -22
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/subgraph/types.d.ts +4 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/composition-version.js +1 -1
- package/dist/v1/federation/federation-factory.js +31 -29
- package/dist/v1/federation/federation-factory.js.map +1 -1
- package/dist/v1/federation/params.d.ts +1 -2
- package/dist/v1/normalization/normalization-factory.d.ts +7 -7
- package/dist/v1/normalization/normalization-factory.js +99 -102
- package/dist/v1/normalization/normalization-factory.js.map +1 -1
- package/dist/v1/normalization/params.d.ts +1 -1
- package/dist/v1/normalization/walkers.js +10 -10
- package/dist/v1/normalization/walkers.js.map +1 -1
- package/package.json +2 -2
|
@@ -88,7 +88,7 @@ class NormalizationFactory {
|
|
|
88
88
|
this.internalGraph = internalGraph;
|
|
89
89
|
this.internalGraph.setSubgraphName(this.subgraphName);
|
|
90
90
|
this.schemaData = {
|
|
91
|
-
|
|
91
|
+
directivesByName: new Map(),
|
|
92
92
|
kind: graphql_1.Kind.SCHEMA_DEFINITION,
|
|
93
93
|
name: string_constants_1.SCHEMA,
|
|
94
94
|
operationTypes: new Map(),
|
|
@@ -188,7 +188,7 @@ class NormalizationFactory {
|
|
|
188
188
|
if (!enumValue) {
|
|
189
189
|
return false;
|
|
190
190
|
}
|
|
191
|
-
return !enumValue.
|
|
191
|
+
return !enumValue.directivesByName.has(string_constants_1.INACCESSIBLE);
|
|
192
192
|
}
|
|
193
193
|
if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
194
194
|
return false;
|
|
@@ -203,32 +203,32 @@ class NormalizationFactory {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
handleFieldInheritableDirectives({
|
|
207
|
-
if (this.doesParentRequireFetchReasons && !
|
|
208
|
-
|
|
206
|
+
handleFieldInheritableDirectives({ directivesByName, fieldName, inheritedDirectiveNames, parentData, }) {
|
|
207
|
+
if (this.doesParentRequireFetchReasons && !directivesByName.has(string_constants_1.REQUIRE_FETCH_REASONS)) {
|
|
208
|
+
directivesByName.set(string_constants_1.REQUIRE_FETCH_REASONS, [(0, utils_5.generateSimpleDirective)(string_constants_1.REQUIRE_FETCH_REASONS)]);
|
|
209
209
|
inheritedDirectiveNames.add(string_constants_1.REQUIRE_FETCH_REASONS);
|
|
210
210
|
}
|
|
211
|
-
if (this.doesParentRequireFetchReasons ||
|
|
211
|
+
if (this.doesParentRequireFetchReasons || directivesByName.has(string_constants_1.REQUIRE_FETCH_REASONS)) {
|
|
212
212
|
parentData.requireFetchReasonsFieldNames.add(fieldName);
|
|
213
213
|
}
|
|
214
214
|
if (!(0, utils_3.isObjectDefinitionData)(parentData)) {
|
|
215
215
|
return;
|
|
216
216
|
}
|
|
217
|
-
if (this.isParentObjectExternal && !
|
|
218
|
-
|
|
217
|
+
if (this.isParentObjectExternal && !directivesByName.has(string_constants_1.EXTERNAL)) {
|
|
218
|
+
directivesByName.set(string_constants_1.EXTERNAL, [(0, utils_5.generateSimpleDirective)(string_constants_1.EXTERNAL)]);
|
|
219
219
|
inheritedDirectiveNames.add(string_constants_1.EXTERNAL);
|
|
220
220
|
}
|
|
221
|
-
if (
|
|
221
|
+
if (directivesByName.has(string_constants_1.EXTERNAL)) {
|
|
222
222
|
this.unvalidatedExternalFieldCoords.add(`${parentData.name}.${fieldName}`);
|
|
223
223
|
}
|
|
224
|
-
if (this.isParentObjectShareable && !
|
|
225
|
-
|
|
224
|
+
if (this.isParentObjectShareable && !directivesByName.has(string_constants_1.SHAREABLE)) {
|
|
225
|
+
directivesByName.set(string_constants_1.SHAREABLE, [(0, utils_5.generateSimpleDirective)(string_constants_1.SHAREABLE)]);
|
|
226
226
|
inheritedDirectiveNames.add(string_constants_1.SHAREABLE);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
extractDirectives(node,
|
|
229
|
+
extractDirectives(node, directivesByName) {
|
|
230
230
|
if (!node.directives) {
|
|
231
|
-
return
|
|
231
|
+
return directivesByName;
|
|
232
232
|
}
|
|
233
233
|
const isCompositeKind = (0, utils_3.isCompositeOutputNodeKind)(node.kind);
|
|
234
234
|
const isObjectKind = (0, utils_3.isObjectNodeKind)(node.kind);
|
|
@@ -236,10 +236,10 @@ class NormalizationFactory {
|
|
|
236
236
|
const directiveName = directiveNode.name.value;
|
|
237
237
|
// Don't create pointless repetitions of @shareable
|
|
238
238
|
if (directiveName === string_constants_1.SHAREABLE) {
|
|
239
|
-
(0, utils_5.getValueOrDefault)(
|
|
239
|
+
(0, utils_5.getValueOrDefault)(directivesByName, directiveName, () => [directiveNode]);
|
|
240
240
|
}
|
|
241
241
|
else {
|
|
242
|
-
(0, utils_5.getValueOrDefault)(
|
|
242
|
+
(0, utils_5.getValueOrDefault)(directivesByName, directiveName, () => []).push(directiveNode);
|
|
243
243
|
}
|
|
244
244
|
if (!isCompositeKind) {
|
|
245
245
|
continue;
|
|
@@ -251,7 +251,7 @@ class NormalizationFactory {
|
|
|
251
251
|
this.isParentObjectExternal ||= directiveName === string_constants_1.EXTERNAL;
|
|
252
252
|
this.isParentObjectShareable ||= directiveName === string_constants_1.SHAREABLE;
|
|
253
253
|
}
|
|
254
|
-
return
|
|
254
|
+
return directivesByName;
|
|
255
255
|
}
|
|
256
256
|
validateDirective({ data, definitionData, directiveCoords, directiveNode, errorMessages, requiredArgumentNames, }) {
|
|
257
257
|
const directiveName = directiveNode.name.value;
|
|
@@ -360,7 +360,7 @@ class NormalizationFactory {
|
|
|
360
360
|
}
|
|
361
361
|
validateDirectives(data, directiveCoords) {
|
|
362
362
|
const undefinedDirectiveNames = new Set();
|
|
363
|
-
for (const [directiveName, directiveNodes] of data.
|
|
363
|
+
for (const [directiveName, directiveNodes] of data.directivesByName) {
|
|
364
364
|
const definitionData = this.directiveDefinitionDataByName.get(directiveName);
|
|
365
365
|
if (!definitionData) {
|
|
366
366
|
if (!undefinedDirectiveNames.has(directiveName)) {
|
|
@@ -432,7 +432,7 @@ class NormalizationFactory {
|
|
|
432
432
|
* as a regular extension.
|
|
433
433
|
* V1 definitions with @extends need a base type.
|
|
434
434
|
*/
|
|
435
|
-
getNodeExtensionType(isRealExtension,
|
|
435
|
+
getNodeExtensionType(isRealExtension, directivesByName, isRootType = false) {
|
|
436
436
|
// If the extend keyword is present, it's simply an extension
|
|
437
437
|
if (isRealExtension) {
|
|
438
438
|
return types_1.ExtensionType.REAL;
|
|
@@ -443,7 +443,7 @@ class NormalizationFactory {
|
|
|
443
443
|
* 2. It's a V2 subgraph (but extends is temporarily propagated to handle @external key fields)
|
|
444
444
|
* 3. And (of course) if @extends isn't defined at all
|
|
445
445
|
*/
|
|
446
|
-
if (isRootType || !
|
|
446
|
+
if (isRootType || !directivesByName.has(string_constants_1.EXTENDS)) {
|
|
447
447
|
return types_1.ExtensionType.NONE;
|
|
448
448
|
}
|
|
449
449
|
// If a V1 non-root Object defines @extends, it is considered an extension across subgraphs.
|
|
@@ -507,12 +507,12 @@ class NormalizationFactory {
|
|
|
507
507
|
data.configureDescriptionDataBySubgraphName.set(this.subgraphName, configureDescriptionData);
|
|
508
508
|
}
|
|
509
509
|
extractConfigureDescriptionsData(data) {
|
|
510
|
-
const configureDescriptionNodes = data.
|
|
510
|
+
const configureDescriptionNodes = data.directivesByName.get(string_constants_1.CONFIGURE_DESCRIPTION);
|
|
511
511
|
if (configureDescriptionNodes && configureDescriptionNodes.length == 1) {
|
|
512
512
|
this.extractConfigureDescriptionData(data, configureDescriptionNodes[0]);
|
|
513
513
|
}
|
|
514
514
|
// TODO configureChildDescriptions will be added in another PR
|
|
515
|
-
// const configureChildDescriptionsNodes = data.
|
|
515
|
+
// const configureChildDescriptionsNodes = data.directivesByName.get(CONFIGURE_CHILD_DESCRIPTIONS);
|
|
516
516
|
// if (configureChildDescriptionsNodes && configureChildDescriptionsNodes.length == 1) {
|
|
517
517
|
// }
|
|
518
518
|
}
|
|
@@ -536,8 +536,8 @@ class NormalizationFactory {
|
|
|
536
536
|
this.extractImplementedInterfaceTypeNames(node, data.implementedInterfaceTypeNames);
|
|
537
537
|
data.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
538
538
|
this.extractConfigureDescriptionsData(data);
|
|
539
|
-
data.isEntity ||= data.
|
|
540
|
-
data.isInaccessible ||= data.
|
|
539
|
+
data.isEntity ||= data.directivesByName.has(string_constants_1.KEY);
|
|
540
|
+
data.isInaccessible ||= data.directivesByName.has(string_constants_1.INACCESSIBLE);
|
|
541
541
|
data.subgraphNames.add(this.subgraphName);
|
|
542
542
|
}
|
|
543
543
|
addConcreteTypeNamesForImplementedInterfaces(interfaceTypeNames, concreteTypeName) {
|
|
@@ -690,11 +690,11 @@ class NormalizationFactory {
|
|
|
690
690
|
}
|
|
691
691
|
return true;
|
|
692
692
|
}
|
|
693
|
-
addFieldDataByNode(fieldDataByFieldName, node, argumentDataByArgumentName,
|
|
693
|
+
addFieldDataByNode(fieldDataByFieldName, node, argumentDataByArgumentName, directivesByName, inheritedDirectiveNames = new Set()) {
|
|
694
694
|
const name = node.name.value;
|
|
695
695
|
const parentTypeName = this.renamedParentTypeName || this.originalParentTypeName;
|
|
696
696
|
const fieldCoords = `${this.originalParentTypeName}.${name}`;
|
|
697
|
-
const { isExternal, isShareable } = (0, utils_4.isNodeExternalOrShareable)(node, !this.isSubgraphVersionTwo,
|
|
697
|
+
const { isExternal, isShareable } = (0, utils_4.isNodeExternalOrShareable)(node, !this.isSubgraphVersionTwo, directivesByName);
|
|
698
698
|
const namedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(node.type);
|
|
699
699
|
const fieldData = {
|
|
700
700
|
argumentDataByName: argumentDataByArgumentName,
|
|
@@ -704,7 +704,7 @@ class NormalizationFactory {
|
|
|
704
704
|
]),
|
|
705
705
|
federatedCoords: `${parentTypeName}.${name}`,
|
|
706
706
|
inheritedDirectiveNames,
|
|
707
|
-
isInaccessible:
|
|
707
|
+
isInaccessible: directivesByName.has(string_constants_1.INACCESSIBLE),
|
|
708
708
|
isShareableBySubgraphName: new Map([[this.subgraphName, isShareable]]),
|
|
709
709
|
kind: graphql_1.Kind.FIELD_DEFINITION,
|
|
710
710
|
name,
|
|
@@ -717,7 +717,7 @@ class NormalizationFactory {
|
|
|
717
717
|
renamedParentTypeName: parentTypeName,
|
|
718
718
|
subgraphNames: new Set([this.subgraphName]),
|
|
719
719
|
type: (0, ast_1.getMutableTypeNode)(node.type, fieldCoords, this.errors),
|
|
720
|
-
|
|
720
|
+
directivesByName: directivesByName,
|
|
721
721
|
description: (0, utils_1.formatDescription)(node.description),
|
|
722
722
|
};
|
|
723
723
|
if (!constants_1.BASE_SCALARS.has(fieldData.namedTypeName)) {
|
|
@@ -743,7 +743,7 @@ class NormalizationFactory {
|
|
|
743
743
|
const namedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(node.type);
|
|
744
744
|
const inputValueData = {
|
|
745
745
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
746
|
-
|
|
746
|
+
directivesByName: this.extractDirectives(node, new Map()),
|
|
747
747
|
federatedCoords,
|
|
748
748
|
fieldName,
|
|
749
749
|
includeDefaultValue: !!node.defaultValue,
|
|
@@ -769,8 +769,8 @@ class NormalizationFactory {
|
|
|
769
769
|
upsertInterfaceDataByNode(node, isRealExtension = false) {
|
|
770
770
|
const typeName = node.name.value;
|
|
771
771
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
772
|
-
const
|
|
773
|
-
const extensionType = this.getNodeExtensionType(isRealExtension,
|
|
772
|
+
const directivesByName = this.extractDirectives(node, parentData?.directivesByName || new Map());
|
|
773
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName);
|
|
774
774
|
const entityInterfaceData = this.entityInterfaceDataByTypeName.get(typeName);
|
|
775
775
|
if (entityInterfaceData && node.fields) {
|
|
776
776
|
for (const fieldNode of node.fields) {
|
|
@@ -787,12 +787,12 @@ class NormalizationFactory {
|
|
|
787
787
|
}
|
|
788
788
|
const newParentData = {
|
|
789
789
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
790
|
-
|
|
790
|
+
directivesByName: directivesByName,
|
|
791
791
|
extensionType,
|
|
792
792
|
fieldDataByName: new Map(),
|
|
793
793
|
implementedInterfaceTypeNames: this.extractImplementedInterfaceTypeNames(node, new Set()),
|
|
794
|
-
isEntity:
|
|
795
|
-
isInaccessible:
|
|
794
|
+
isEntity: directivesByName.has(string_constants_1.KEY),
|
|
795
|
+
isInaccessible: directivesByName.has(string_constants_1.INACCESSIBLE),
|
|
796
796
|
kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
|
|
797
797
|
name: typeName,
|
|
798
798
|
node: (0, ast_1.getMutableInterfaceNode)(node.name),
|
|
@@ -831,9 +831,9 @@ class NormalizationFactory {
|
|
|
831
831
|
upsertObjectDataByNode(node, isRealExtension = false) {
|
|
832
832
|
const typeName = node.name.value;
|
|
833
833
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
834
|
-
const
|
|
834
|
+
const directivesByName = this.extractDirectives(node, parentData?.directivesByName ?? new Map());
|
|
835
835
|
const isRootType = this.isTypeNameRootType(typeName);
|
|
836
|
-
const extensionType = this.getNodeExtensionType(isRealExtension,
|
|
836
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName, isRootType);
|
|
837
837
|
this.addInterfaceObjectFieldsByNode(node);
|
|
838
838
|
if (parentData) {
|
|
839
839
|
if (parentData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
@@ -841,23 +841,23 @@ class NormalizationFactory {
|
|
|
841
841
|
return;
|
|
842
842
|
}
|
|
843
843
|
this.updateCompositeOutputDataByNode(node, parentData, extensionType);
|
|
844
|
-
if (!
|
|
844
|
+
if (!directivesByName.has(string_constants_1.INTERFACE_OBJECT)) {
|
|
845
845
|
this.addConcreteTypeNamesForImplementedInterfaces(parentData.implementedInterfaceTypeNames, typeName);
|
|
846
846
|
}
|
|
847
847
|
return;
|
|
848
848
|
}
|
|
849
849
|
const implementedInterfaceTypeNames = this.extractImplementedInterfaceTypeNames(node, new Set());
|
|
850
|
-
if (!
|
|
850
|
+
if (!directivesByName.has(string_constants_1.INTERFACE_OBJECT)) {
|
|
851
851
|
this.addConcreteTypeNamesForImplementedInterfaces(implementedInterfaceTypeNames, typeName);
|
|
852
852
|
}
|
|
853
853
|
const newParentData = {
|
|
854
854
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
855
|
-
|
|
855
|
+
directivesByName: directivesByName,
|
|
856
856
|
extensionType,
|
|
857
857
|
fieldDataByName: new Map(),
|
|
858
858
|
implementedInterfaceTypeNames,
|
|
859
|
-
isEntity:
|
|
860
|
-
isInaccessible:
|
|
859
|
+
isEntity: directivesByName.has(string_constants_1.KEY),
|
|
860
|
+
isInaccessible: directivesByName.has(string_constants_1.INACCESSIBLE),
|
|
861
861
|
isRootType,
|
|
862
862
|
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
|
863
863
|
name: typeName,
|
|
@@ -875,15 +875,15 @@ class NormalizationFactory {
|
|
|
875
875
|
const typeName = node.name.value;
|
|
876
876
|
this.internalGraph.addOrUpdateNode(typeName, { isLeaf: true });
|
|
877
877
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
878
|
-
const
|
|
879
|
-
const extensionType = this.getNodeExtensionType(isRealExtension,
|
|
878
|
+
const directivesByName = this.extractDirectives(node, parentData?.directivesByName || new Map());
|
|
879
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName);
|
|
880
880
|
if (parentData) {
|
|
881
881
|
if (parentData.kind !== graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
|
882
882
|
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_5.kindToNodeType)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
883
883
|
return;
|
|
884
884
|
}
|
|
885
885
|
this.setParentDataExtensionType(parentData, extensionType);
|
|
886
|
-
parentData.isInaccessible ||=
|
|
886
|
+
parentData.isInaccessible ||= directivesByName.has(string_constants_1.INACCESSIBLE);
|
|
887
887
|
parentData.subgraphNames.add(this.subgraphName);
|
|
888
888
|
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
889
889
|
this.extractConfigureDescriptionsData(parentData);
|
|
@@ -892,10 +892,10 @@ class NormalizationFactory {
|
|
|
892
892
|
const newParentData = {
|
|
893
893
|
appearances: 1,
|
|
894
894
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
895
|
-
|
|
895
|
+
directivesByName: directivesByName,
|
|
896
896
|
extensionType,
|
|
897
897
|
enumValueDataByName: new Map(),
|
|
898
|
-
isInaccessible:
|
|
898
|
+
isInaccessible: directivesByName.has(string_constants_1.INACCESSIBLE),
|
|
899
899
|
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
|
|
900
900
|
name: typeName,
|
|
901
901
|
node: (0, ast_1.getMutableEnumNode)(node.name),
|
|
@@ -909,8 +909,8 @@ class NormalizationFactory {
|
|
|
909
909
|
upsertInputObjectByNode(node, isRealExtension = false) {
|
|
910
910
|
const typeName = node.name.value;
|
|
911
911
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
912
|
-
const
|
|
913
|
-
const extensionType = this.getNodeExtensionType(isRealExtension,
|
|
912
|
+
const directivesByName = this.extractDirectives(node, parentData?.directivesByName || new Map());
|
|
913
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName);
|
|
914
914
|
if (parentData) {
|
|
915
915
|
if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
916
916
|
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_5.kindToNodeType)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
@@ -919,7 +919,7 @@ class NormalizationFactory {
|
|
|
919
919
|
};
|
|
920
920
|
}
|
|
921
921
|
this.setParentDataExtensionType(parentData, extensionType);
|
|
922
|
-
parentData.isInaccessible ||=
|
|
922
|
+
parentData.isInaccessible ||= directivesByName.has(string_constants_1.INACCESSIBLE);
|
|
923
923
|
parentData.subgraphNames.add(this.subgraphName);
|
|
924
924
|
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
925
925
|
this.extractConfigureDescriptionsData(parentData);
|
|
@@ -930,10 +930,10 @@ class NormalizationFactory {
|
|
|
930
930
|
}
|
|
931
931
|
const newParentData = {
|
|
932
932
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
933
|
-
|
|
933
|
+
directivesByName: directivesByName,
|
|
934
934
|
extensionType,
|
|
935
935
|
inputValueDataByName: new Map(),
|
|
936
|
-
isInaccessible:
|
|
936
|
+
isInaccessible: directivesByName.has(string_constants_1.INACCESSIBLE),
|
|
937
937
|
kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
938
938
|
name: typeName,
|
|
939
939
|
node: (0, ast_1.getMutableInputObjectNode)(node.name),
|
|
@@ -952,8 +952,8 @@ class NormalizationFactory {
|
|
|
952
952
|
const typeName = node.name.value;
|
|
953
953
|
this.internalGraph.addOrUpdateNode(typeName, { isLeaf: true });
|
|
954
954
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
955
|
-
const
|
|
956
|
-
const extensionType = this.getNodeExtensionType(isRealExtension,
|
|
955
|
+
const directivesByName = this.extractDirectives(node, parentData?.directivesByName || new Map());
|
|
956
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName);
|
|
957
957
|
if (parentData) {
|
|
958
958
|
if (parentData.kind !== graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
|
|
959
959
|
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_5.kindToNodeType)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
@@ -967,7 +967,7 @@ class NormalizationFactory {
|
|
|
967
967
|
}
|
|
968
968
|
const newParentData = {
|
|
969
969
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
970
|
-
|
|
970
|
+
directivesByName: directivesByName,
|
|
971
971
|
extensionType,
|
|
972
972
|
kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
|
|
973
973
|
name: typeName,
|
|
@@ -1007,8 +1007,8 @@ class NormalizationFactory {
|
|
|
1007
1007
|
upsertUnionByNode(node, isRealExtension = false) {
|
|
1008
1008
|
const typeName = node.name.value;
|
|
1009
1009
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
1010
|
-
const
|
|
1011
|
-
const extensionType = this.getNodeExtensionType(isRealExtension,
|
|
1010
|
+
const directivesByName = this.extractDirectives(node, parentData?.directivesByName || new Map());
|
|
1011
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName);
|
|
1012
1012
|
// Also adds the concrete type name edges to the internal graph
|
|
1013
1013
|
this.addConcreteTypeNamesForUnion(node);
|
|
1014
1014
|
if (parentData) {
|
|
@@ -1025,7 +1025,7 @@ class NormalizationFactory {
|
|
|
1025
1025
|
}
|
|
1026
1026
|
const newParentData = {
|
|
1027
1027
|
configureDescriptionDataBySubgraphName: new Map(),
|
|
1028
|
-
|
|
1028
|
+
directivesByName: directivesByName,
|
|
1029
1029
|
extensionType,
|
|
1030
1030
|
kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
|
|
1031
1031
|
memberByMemberTypeName: this.extractUnionMembers(node, new Map()),
|
|
@@ -1404,7 +1404,7 @@ class NormalizationFactory {
|
|
|
1404
1404
|
if (data.implementedInterfaceTypeNames.size < 1) {
|
|
1405
1405
|
return;
|
|
1406
1406
|
}
|
|
1407
|
-
const isParentInaccessible = data.
|
|
1407
|
+
const isParentInaccessible = data.directivesByName.has(string_constants_1.INACCESSIBLE);
|
|
1408
1408
|
const implementationErrorsMap = new Map();
|
|
1409
1409
|
const invalidImplementationTypeStringByTypeName = new Map();
|
|
1410
1410
|
let doesInterfaceImplementItself = false;
|
|
@@ -2006,7 +2006,7 @@ class NormalizationFactory {
|
|
|
2006
2006
|
const fieldCoords = `${fieldData.originalParentTypeName}.${fieldName}`;
|
|
2007
2007
|
const definedEventsDirectiveNames = new Set();
|
|
2008
2008
|
for (const eventsDirectiveName of strings_1.EVENT_DIRECTIVE_NAMES) {
|
|
2009
|
-
if (fieldData.
|
|
2009
|
+
if (fieldData.directivesByName.has(eventsDirectiveName)) {
|
|
2010
2010
|
definedEventsDirectiveNames.add(eventsDirectiveName);
|
|
2011
2011
|
}
|
|
2012
2012
|
}
|
|
@@ -2265,9 +2265,9 @@ class NormalizationFactory {
|
|
|
2265
2265
|
}
|
|
2266
2266
|
}
|
|
2267
2267
|
}
|
|
2268
|
-
getValidFlattenedDirectiveArray(
|
|
2268
|
+
getValidFlattenedDirectiveArray(directivesByName, directiveCoords, removeInheritedDirectives = false) {
|
|
2269
2269
|
const flattenedArray = [];
|
|
2270
|
-
for (const [directiveName, directiveNodes] of
|
|
2270
|
+
for (const [directiveName, directiveNodes] of directivesByName) {
|
|
2271
2271
|
if (removeInheritedDirectives && string_constants_1.INHERITABLE_DIRECTIVE_NAMES.has(directiveName)) {
|
|
2272
2272
|
continue;
|
|
2273
2273
|
}
|
|
@@ -2305,62 +2305,67 @@ class NormalizationFactory {
|
|
|
2305
2305
|
flattenedArray.push(keyDirectiveNode);
|
|
2306
2306
|
normalizedDirectiveNodes.push(keyDirectiveNode);
|
|
2307
2307
|
}
|
|
2308
|
-
|
|
2308
|
+
directivesByName.set(directiveName, normalizedDirectiveNodes);
|
|
2309
2309
|
}
|
|
2310
2310
|
return flattenedArray;
|
|
2311
2311
|
}
|
|
2312
2312
|
getEnumNodeByData(enumDefinitionData) {
|
|
2313
2313
|
enumDefinitionData.node.description = enumDefinitionData.description;
|
|
2314
|
-
enumDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(enumDefinitionData.
|
|
2314
|
+
enumDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(enumDefinitionData.directivesByName, enumDefinitionData.name);
|
|
2315
2315
|
enumDefinitionData.node.values = (0, utils_4.childMapToValueArray)(enumDefinitionData.enumValueDataByName);
|
|
2316
2316
|
return enumDefinitionData.node;
|
|
2317
2317
|
}
|
|
2318
2318
|
getInputObjectNodeByData(inputObjectDefinitionData) {
|
|
2319
2319
|
inputObjectDefinitionData.node.description = inputObjectDefinitionData.description;
|
|
2320
|
-
inputObjectDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(inputObjectDefinitionData.
|
|
2320
|
+
inputObjectDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(inputObjectDefinitionData.directivesByName, inputObjectDefinitionData.name);
|
|
2321
2321
|
inputObjectDefinitionData.node.fields = (0, utils_4.childMapToValueArray)(inputObjectDefinitionData.inputValueDataByName);
|
|
2322
2322
|
return inputObjectDefinitionData.node;
|
|
2323
2323
|
}
|
|
2324
2324
|
getCompositeOutputNodeByData(compositeOutputData) {
|
|
2325
2325
|
compositeOutputData.node.description = compositeOutputData.description;
|
|
2326
|
-
compositeOutputData.node.directives = this.getValidFlattenedDirectiveArray(compositeOutputData.
|
|
2326
|
+
compositeOutputData.node.directives = this.getValidFlattenedDirectiveArray(compositeOutputData.directivesByName, compositeOutputData.name, true);
|
|
2327
2327
|
compositeOutputData.node.fields = (0, utils_4.childMapToValueArray)(compositeOutputData.fieldDataByName);
|
|
2328
2328
|
compositeOutputData.node.interfaces = (0, utils_1.setToNamedTypeNodeArray)(compositeOutputData.implementedInterfaceTypeNames);
|
|
2329
2329
|
return compositeOutputData.node;
|
|
2330
2330
|
}
|
|
2331
2331
|
getScalarNodeByData(scalarDefinitionData) {
|
|
2332
2332
|
scalarDefinitionData.node.description = scalarDefinitionData.description;
|
|
2333
|
-
scalarDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(scalarDefinitionData.
|
|
2333
|
+
scalarDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(scalarDefinitionData.directivesByName, scalarDefinitionData.name);
|
|
2334
2334
|
return scalarDefinitionData.node;
|
|
2335
2335
|
}
|
|
2336
2336
|
getSchemaNodeByData(schemaData) {
|
|
2337
2337
|
const operationTypes = [];
|
|
2338
|
-
for (const
|
|
2339
|
-
const
|
|
2340
|
-
if (
|
|
2341
|
-
operationTypes.push(node);
|
|
2342
|
-
continue;
|
|
2343
|
-
}
|
|
2344
|
-
const defaultRootTypeName = (0, utils_5.getOrThrowError)(utils_1.operationTypeNodeToDefaultType, operationTypeNode, 'operationTypeNodeToDefaultType');
|
|
2345
|
-
if (!this.parentDefinitionDataByTypeName.has(defaultRootTypeName)) {
|
|
2338
|
+
for (const [operation, { type: { name: { value }, }, },] of schemaData.operationTypes) {
|
|
2339
|
+
const data = this.parentDefinitionDataByTypeName.get(value);
|
|
2340
|
+
if (!data || !(0, utils_3.isObjectDefinitionData)(data)) {
|
|
2346
2341
|
continue;
|
|
2347
2342
|
}
|
|
2348
2343
|
operationTypes.push({
|
|
2349
2344
|
kind: graphql_1.Kind.OPERATION_TYPE_DEFINITION,
|
|
2350
|
-
operation
|
|
2351
|
-
type: (0, utils_1.stringToNamedTypeNode)(
|
|
2345
|
+
operation,
|
|
2346
|
+
type: (0, utils_1.stringToNamedTypeNode)(value),
|
|
2352
2347
|
});
|
|
2353
2348
|
}
|
|
2349
|
+
if (operationTypes.length > 0) {
|
|
2350
|
+
const node = {
|
|
2351
|
+
...(schemaData.description ? { description: schemaData.description } : {}),
|
|
2352
|
+
directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
|
|
2353
|
+
kind: graphql_1.Kind.SCHEMA_DEFINITION,
|
|
2354
|
+
operationTypes: operationTypes,
|
|
2355
|
+
};
|
|
2356
|
+
return node;
|
|
2357
|
+
}
|
|
2358
|
+
if (schemaData.directivesByName.size < 1) {
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2354
2361
|
return {
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
kind: schemaData.kind,
|
|
2358
|
-
operationTypes,
|
|
2362
|
+
directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
|
|
2363
|
+
kind: graphql_1.Kind.SCHEMA_EXTENSION,
|
|
2359
2364
|
};
|
|
2360
2365
|
}
|
|
2361
2366
|
getUnionNodeByData(unionDefinitionData) {
|
|
2362
2367
|
unionDefinitionData.node.description = unionDefinitionData.description;
|
|
2363
|
-
unionDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(unionDefinitionData.
|
|
2368
|
+
unionDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(unionDefinitionData.directivesByName, unionDefinitionData.name);
|
|
2364
2369
|
unionDefinitionData.node.types = (0, utils_3.mapToArrayOfValues)(unionDefinitionData.memberByMemberTypeName);
|
|
2365
2370
|
return unionDefinitionData.node;
|
|
2366
2371
|
}
|
|
@@ -2538,7 +2543,7 @@ class NormalizationFactory {
|
|
|
2538
2543
|
}
|
|
2539
2544
|
}
|
|
2540
2545
|
validateOneOfDirective({ data, requiredFieldNames }) {
|
|
2541
|
-
if (!data.
|
|
2546
|
+
if (!data.directivesByName.has(string_constants_1.ONE_OF)) {
|
|
2542
2547
|
return true;
|
|
2543
2548
|
}
|
|
2544
2549
|
if (requiredFieldNames.size > 0) {
|
|
@@ -2577,25 +2582,6 @@ class NormalizationFactory {
|
|
|
2577
2582
|
}
|
|
2578
2583
|
definitions.push(...dependencies);
|
|
2579
2584
|
}
|
|
2580
|
-
#addSchemaDefinitionNode(definitions) {
|
|
2581
|
-
const schemaNode = this.getSchemaNodeByData(this.schemaData);
|
|
2582
|
-
if (schemaNode.operationTypes.length > 0) {
|
|
2583
|
-
definitions.push(schemaNode);
|
|
2584
|
-
return schemaNode;
|
|
2585
|
-
}
|
|
2586
|
-
if (!schemaNode.directives?.length) {
|
|
2587
|
-
return;
|
|
2588
|
-
}
|
|
2589
|
-
return {
|
|
2590
|
-
directives: schemaNode.directives,
|
|
2591
|
-
kind: graphql_1.Kind.SCHEMA_EXTENSION,
|
|
2592
|
-
};
|
|
2593
|
-
// @TODO this currently breaks engine
|
|
2594
|
-
// definitions.push({
|
|
2595
|
-
// directives: schemaNode.directives,
|
|
2596
|
-
// kind: Kind.SCHEMA_EXTENSION,
|
|
2597
|
-
// });
|
|
2598
|
-
}
|
|
2599
2585
|
normalize(document) {
|
|
2600
2586
|
// Collect any renamed root types
|
|
2601
2587
|
(0, walkers_1.upsertDirectiveSchemaAndEntityDefinitions)(this, document);
|
|
@@ -2603,7 +2589,15 @@ class NormalizationFactory {
|
|
|
2603
2589
|
const definitions = [];
|
|
2604
2590
|
this.#addDirectiveDefinitionsToDocument(definitions);
|
|
2605
2591
|
this.validateDirectives(this.schemaData, string_constants_1.SCHEMA);
|
|
2606
|
-
const schemaNode = this
|
|
2592
|
+
const schemaNode = this.getSchemaNodeByData(this.schemaData);
|
|
2593
|
+
/* Schema extension orphans are not supported on old routers.
|
|
2594
|
+
* Consequently, it is a breaking change that requires a new composition version, and hat composition version
|
|
2595
|
+
* would only be compatible with newer routers that support schema extension orphans.
|
|
2596
|
+
* For now, only a valid schema definition node is pushed.
|
|
2597
|
+
*/
|
|
2598
|
+
if (schemaNode?.kind === graphql_1.Kind.SCHEMA_DEFINITION) {
|
|
2599
|
+
definitions.push(schemaNode);
|
|
2600
|
+
}
|
|
2607
2601
|
for (const [parentTypeName, parentData] of this.parentDefinitionDataByTypeName) {
|
|
2608
2602
|
this.validateDirectives(parentData, parentTypeName);
|
|
2609
2603
|
}
|
|
@@ -2739,7 +2733,10 @@ class NormalizationFactory {
|
|
|
2739
2733
|
this.addFieldNamesToConfigurationData(parentData.fieldDataByName, configurationData);
|
|
2740
2734
|
this.validateInterfaceImplementations(parentData);
|
|
2741
2735
|
definitions.push(this.getCompositeOutputNodeByData(parentData));
|
|
2742
|
-
|
|
2736
|
+
/* Interfaces and Objects must define at least one field.
|
|
2737
|
+
* However, some servers allow a query root type to be defined without fields.
|
|
2738
|
+
* This is so it can be renamed and any federation boiler plate is appended to that renamed node.
|
|
2739
|
+
* */
|
|
2743
2740
|
if (parentData.fieldDataByName.size < 1 && !(0, utils_2.isNodeQuery)(parentTypeName, operationTypeNode)) {
|
|
2744
2741
|
this.errors.push((0, errors_1.noFieldDefinitionsError)((0, utils_5.kindToNodeType)(parentData.kind), parentTypeName));
|
|
2745
2742
|
}
|