@wundergraph/composition 0.48.3 → 0.48.5
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 +4 -3
- package/dist/errors/errors.js +15 -6
- package/dist/errors/errors.js.map +1 -1
- package/dist/errors/types.d.ts +14 -2
- 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/utils/string-constants.d.ts +2 -1
- package/dist/utils/string-constants.js +5 -4
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/v1/federation/federation-factory.js +36 -34
- package/dist/v1/federation/federation-factory.js.map +1 -1
- package/dist/v1/federation/params.d.ts +1 -2
- package/dist/v1/federation/utils.js +4 -0
- package/dist/v1/federation/utils.js.map +1 -1
- package/dist/v1/normalization/normalization-factory.d.ts +7 -7
- package/dist/v1/normalization/normalization-factory.js +157 -112
- package/dist/v1/normalization/normalization-factory.js.map +1 -1
- package/dist/v1/normalization/params.d.ts +7 -1
- package/dist/v1/normalization/utils.js +9 -2
- package/dist/v1/normalization/utils.js.map +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()),
|
|
@@ -1106,20 +1106,51 @@ class NormalizationFactory {
|
|
|
1106
1106
|
}
|
|
1107
1107
|
const fieldData = (0, utils_5.getOrThrowError)(parentData.fieldDataByName, fieldName, `${parentTypeName}.fieldDataByFieldName`);
|
|
1108
1108
|
const fieldNamedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(fieldData.node.type);
|
|
1109
|
+
const fieldCoords = `${parentTypeName}.${fieldName}`;
|
|
1110
|
+
if (constants_1.BASE_SCALARS.has(fieldNamedTypeName)) {
|
|
1111
|
+
return {
|
|
1112
|
+
errorString: (0, errors_1.incompatibleTypeWithProvidesErrorMessage)({
|
|
1113
|
+
fieldCoords,
|
|
1114
|
+
responseType: fieldNamedTypeName,
|
|
1115
|
+
subgraphName: this.subgraphName,
|
|
1116
|
+
}),
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1109
1119
|
const namedTypeData = this.parentDefinitionDataByTypeName.get(fieldNamedTypeName);
|
|
1110
1120
|
// This error should never happen
|
|
1111
1121
|
if (!namedTypeData) {
|
|
1112
1122
|
return {
|
|
1113
|
-
errorString: (0, errors_1.unknownNamedTypeErrorMessage)(
|
|
1123
|
+
errorString: (0, errors_1.unknownNamedTypeErrorMessage)(fieldCoords, fieldNamedTypeName),
|
|
1114
1124
|
};
|
|
1115
1125
|
}
|
|
1126
|
+
// @TODO handle abstract types and fragments
|
|
1116
1127
|
if (namedTypeData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION && namedTypeData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
1117
1128
|
return {
|
|
1118
|
-
errorString: (0, errors_1.incompatibleTypeWithProvidesErrorMessage)(
|
|
1129
|
+
errorString: (0, errors_1.incompatibleTypeWithProvidesErrorMessage)({
|
|
1130
|
+
fieldCoords,
|
|
1131
|
+
responseType: fieldNamedTypeName,
|
|
1132
|
+
subgraphName: this.subgraphName,
|
|
1133
|
+
}),
|
|
1119
1134
|
};
|
|
1120
1135
|
}
|
|
1121
1136
|
return { fieldSetParentData: namedTypeData };
|
|
1122
1137
|
}
|
|
1138
|
+
#handleNonExternalConditionalField({ currentFieldCoords, directiveCoords, directiveName, fieldSet, }) {
|
|
1139
|
+
if (this.isSubgraphVersionTwo) {
|
|
1140
|
+
this.errors.push((0, errors_1.nonExternalConditionalFieldError)({
|
|
1141
|
+
directiveCoords,
|
|
1142
|
+
directiveName,
|
|
1143
|
+
fieldSet,
|
|
1144
|
+
subgraphName: this.subgraphName,
|
|
1145
|
+
targetCoords: currentFieldCoords,
|
|
1146
|
+
}));
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
/* In V1, @requires and @provides do not need to declare any part of the field set @external.
|
|
1150
|
+
* It would appear that any such non-external fields are treated as if they are non-conditionally provided.
|
|
1151
|
+
* */
|
|
1152
|
+
this.warnings.push((0, warnings_1.nonExternalConditionalFieldWarning)(directiveCoords, this.subgraphName, currentFieldCoords, fieldSet, directiveName));
|
|
1153
|
+
}
|
|
1123
1154
|
validateConditionalFieldSet(selectionSetParentData, fieldSet, directiveFieldName, isProvides, directiveParentTypeName) {
|
|
1124
1155
|
// Create a new selection set so that the value can be parsed as a new DocumentNode
|
|
1125
1156
|
const { error, documentNode } = (0, utils_1.safeParse)('{' + fieldSet + '}');
|
|
@@ -1164,6 +1195,21 @@ class NormalizationFactory {
|
|
|
1164
1195
|
fieldCoordsPath.push(currentFieldCoords);
|
|
1165
1196
|
fieldPath.push(fieldName);
|
|
1166
1197
|
lastFieldName = fieldName;
|
|
1198
|
+
if (fieldName === string_constants_1.TYPENAME) {
|
|
1199
|
+
if (isProvides) {
|
|
1200
|
+
errorMessages.push((0, errors_1.typeNameAlreadyProvidedErrorMessage)(currentFieldCoords, nf.subgraphName));
|
|
1201
|
+
return graphql_1.BREAK;
|
|
1202
|
+
}
|
|
1203
|
+
if (externalAncestors.size < 1) {
|
|
1204
|
+
nf.#handleNonExternalConditionalField({
|
|
1205
|
+
currentFieldCoords,
|
|
1206
|
+
directiveCoords,
|
|
1207
|
+
directiveName,
|
|
1208
|
+
fieldSet,
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1167
1213
|
const fieldData = parentData.fieldDataByName.get(fieldName);
|
|
1168
1214
|
// undefined if the field does not exist on the parent
|
|
1169
1215
|
if (!fieldData) {
|
|
@@ -1188,14 +1234,12 @@ class NormalizationFactory {
|
|
|
1188
1234
|
namedTypeData?.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION ||
|
|
1189
1235
|
namedTypeData?.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
|
1190
1236
|
if (externalAncestors.size < 1 && !isDefinedExternal) {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
* */
|
|
1198
|
-
nf.warnings.push((0, warnings_1.nonExternalConditionalFieldWarning)(directiveCoords, nf.subgraphName, currentFieldCoords, fieldSet, directiveName));
|
|
1237
|
+
nf.#handleNonExternalConditionalField({
|
|
1238
|
+
currentFieldCoords,
|
|
1239
|
+
directiveCoords,
|
|
1240
|
+
directiveName,
|
|
1241
|
+
fieldSet,
|
|
1242
|
+
});
|
|
1199
1243
|
return;
|
|
1200
1244
|
}
|
|
1201
1245
|
if (externalAncestors.size < 1 && isUnconditionallyProvided) {
|
|
@@ -1315,6 +1359,10 @@ class NormalizationFactory {
|
|
|
1315
1359
|
errorMessages.push((0, errors_1.unparsableFieldSetSelectionErrorMessage)(fieldSet, lastFieldName));
|
|
1316
1360
|
return graphql_1.BREAK;
|
|
1317
1361
|
}
|
|
1362
|
+
if (lastFieldName === string_constants_1.TYPENAME) {
|
|
1363
|
+
errorMessages.push((0, errors_1.invalidSelectionSetDefinitionErrorMessage)(fieldSet, fieldCoordsPath, string_constants_1.STRING_SCALAR, (0, utils_5.kindToNodeType)(graphql_1.Kind.SCALAR_TYPE_DEFINITION)));
|
|
1364
|
+
return graphql_1.BREAK;
|
|
1365
|
+
}
|
|
1318
1366
|
const fieldData = parentData.fieldDataByName.get(lastFieldName);
|
|
1319
1367
|
if (!fieldData) {
|
|
1320
1368
|
errorMessages.push((0, errors_1.undefinedFieldInFieldSetErrorMessage)(fieldSet, parentData.name, lastFieldName));
|
|
@@ -1404,7 +1452,7 @@ class NormalizationFactory {
|
|
|
1404
1452
|
if (data.implementedInterfaceTypeNames.size < 1) {
|
|
1405
1453
|
return;
|
|
1406
1454
|
}
|
|
1407
|
-
const isParentInaccessible = data.
|
|
1455
|
+
const isParentInaccessible = data.directivesByName.has(string_constants_1.INACCESSIBLE);
|
|
1408
1456
|
const implementationErrorsMap = new Map();
|
|
1409
1457
|
const invalidImplementationTypeStringByTypeName = new Map();
|
|
1410
1458
|
let doesInterfaceImplementItself = false;
|
|
@@ -2006,7 +2054,7 @@ class NormalizationFactory {
|
|
|
2006
2054
|
const fieldCoords = `${fieldData.originalParentTypeName}.${fieldName}`;
|
|
2007
2055
|
const definedEventsDirectiveNames = new Set();
|
|
2008
2056
|
for (const eventsDirectiveName of strings_1.EVENT_DIRECTIVE_NAMES) {
|
|
2009
|
-
if (fieldData.
|
|
2057
|
+
if (fieldData.directivesByName.has(eventsDirectiveName)) {
|
|
2010
2058
|
definedEventsDirectiveNames.add(eventsDirectiveName);
|
|
2011
2059
|
}
|
|
2012
2060
|
}
|
|
@@ -2265,9 +2313,9 @@ class NormalizationFactory {
|
|
|
2265
2313
|
}
|
|
2266
2314
|
}
|
|
2267
2315
|
}
|
|
2268
|
-
getValidFlattenedDirectiveArray(
|
|
2316
|
+
getValidFlattenedDirectiveArray(directivesByName, directiveCoords, removeInheritedDirectives = false) {
|
|
2269
2317
|
const flattenedArray = [];
|
|
2270
|
-
for (const [directiveName, directiveNodes] of
|
|
2318
|
+
for (const [directiveName, directiveNodes] of directivesByName) {
|
|
2271
2319
|
if (removeInheritedDirectives && string_constants_1.INHERITABLE_DIRECTIVE_NAMES.has(directiveName)) {
|
|
2272
2320
|
continue;
|
|
2273
2321
|
}
|
|
@@ -2305,62 +2353,67 @@ class NormalizationFactory {
|
|
|
2305
2353
|
flattenedArray.push(keyDirectiveNode);
|
|
2306
2354
|
normalizedDirectiveNodes.push(keyDirectiveNode);
|
|
2307
2355
|
}
|
|
2308
|
-
|
|
2356
|
+
directivesByName.set(directiveName, normalizedDirectiveNodes);
|
|
2309
2357
|
}
|
|
2310
2358
|
return flattenedArray;
|
|
2311
2359
|
}
|
|
2312
2360
|
getEnumNodeByData(enumDefinitionData) {
|
|
2313
2361
|
enumDefinitionData.node.description = enumDefinitionData.description;
|
|
2314
|
-
enumDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(enumDefinitionData.
|
|
2362
|
+
enumDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(enumDefinitionData.directivesByName, enumDefinitionData.name);
|
|
2315
2363
|
enumDefinitionData.node.values = (0, utils_4.childMapToValueArray)(enumDefinitionData.enumValueDataByName);
|
|
2316
2364
|
return enumDefinitionData.node;
|
|
2317
2365
|
}
|
|
2318
2366
|
getInputObjectNodeByData(inputObjectDefinitionData) {
|
|
2319
2367
|
inputObjectDefinitionData.node.description = inputObjectDefinitionData.description;
|
|
2320
|
-
inputObjectDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(inputObjectDefinitionData.
|
|
2368
|
+
inputObjectDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(inputObjectDefinitionData.directivesByName, inputObjectDefinitionData.name);
|
|
2321
2369
|
inputObjectDefinitionData.node.fields = (0, utils_4.childMapToValueArray)(inputObjectDefinitionData.inputValueDataByName);
|
|
2322
2370
|
return inputObjectDefinitionData.node;
|
|
2323
2371
|
}
|
|
2324
2372
|
getCompositeOutputNodeByData(compositeOutputData) {
|
|
2325
2373
|
compositeOutputData.node.description = compositeOutputData.description;
|
|
2326
|
-
compositeOutputData.node.directives = this.getValidFlattenedDirectiveArray(compositeOutputData.
|
|
2374
|
+
compositeOutputData.node.directives = this.getValidFlattenedDirectiveArray(compositeOutputData.directivesByName, compositeOutputData.name, true);
|
|
2327
2375
|
compositeOutputData.node.fields = (0, utils_4.childMapToValueArray)(compositeOutputData.fieldDataByName);
|
|
2328
2376
|
compositeOutputData.node.interfaces = (0, utils_1.setToNamedTypeNodeArray)(compositeOutputData.implementedInterfaceTypeNames);
|
|
2329
2377
|
return compositeOutputData.node;
|
|
2330
2378
|
}
|
|
2331
2379
|
getScalarNodeByData(scalarDefinitionData) {
|
|
2332
2380
|
scalarDefinitionData.node.description = scalarDefinitionData.description;
|
|
2333
|
-
scalarDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(scalarDefinitionData.
|
|
2381
|
+
scalarDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(scalarDefinitionData.directivesByName, scalarDefinitionData.name);
|
|
2334
2382
|
return scalarDefinitionData.node;
|
|
2335
2383
|
}
|
|
2336
2384
|
getSchemaNodeByData(schemaData) {
|
|
2337
2385
|
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)) {
|
|
2386
|
+
for (const [operation, { type: { name: { value }, }, },] of schemaData.operationTypes) {
|
|
2387
|
+
const data = this.parentDefinitionDataByTypeName.get(value);
|
|
2388
|
+
if (!data || !(0, utils_3.isObjectDefinitionData)(data)) {
|
|
2346
2389
|
continue;
|
|
2347
2390
|
}
|
|
2348
2391
|
operationTypes.push({
|
|
2349
2392
|
kind: graphql_1.Kind.OPERATION_TYPE_DEFINITION,
|
|
2350
|
-
operation
|
|
2351
|
-
type: (0, utils_1.stringToNamedTypeNode)(
|
|
2393
|
+
operation,
|
|
2394
|
+
type: (0, utils_1.stringToNamedTypeNode)(value),
|
|
2352
2395
|
});
|
|
2353
2396
|
}
|
|
2397
|
+
if (operationTypes.length > 0) {
|
|
2398
|
+
const node = {
|
|
2399
|
+
...(schemaData.description ? { description: schemaData.description } : {}),
|
|
2400
|
+
directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
|
|
2401
|
+
kind: graphql_1.Kind.SCHEMA_DEFINITION,
|
|
2402
|
+
operationTypes: operationTypes,
|
|
2403
|
+
};
|
|
2404
|
+
return node;
|
|
2405
|
+
}
|
|
2406
|
+
if (schemaData.directivesByName.size < 1) {
|
|
2407
|
+
return;
|
|
2408
|
+
}
|
|
2354
2409
|
return {
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
kind: schemaData.kind,
|
|
2358
|
-
operationTypes,
|
|
2410
|
+
directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
|
|
2411
|
+
kind: graphql_1.Kind.SCHEMA_EXTENSION,
|
|
2359
2412
|
};
|
|
2360
2413
|
}
|
|
2361
2414
|
getUnionNodeByData(unionDefinitionData) {
|
|
2362
2415
|
unionDefinitionData.node.description = unionDefinitionData.description;
|
|
2363
|
-
unionDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(unionDefinitionData.
|
|
2416
|
+
unionDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(unionDefinitionData.directivesByName, unionDefinitionData.name);
|
|
2364
2417
|
unionDefinitionData.node.types = (0, utils_3.mapToArrayOfValues)(unionDefinitionData.memberByMemberTypeName);
|
|
2365
2418
|
return unionDefinitionData.node;
|
|
2366
2419
|
}
|
|
@@ -2538,7 +2591,7 @@ class NormalizationFactory {
|
|
|
2538
2591
|
}
|
|
2539
2592
|
}
|
|
2540
2593
|
validateOneOfDirective({ data, requiredFieldNames }) {
|
|
2541
|
-
if (!data.
|
|
2594
|
+
if (!data.directivesByName.has(string_constants_1.ONE_OF)) {
|
|
2542
2595
|
return true;
|
|
2543
2596
|
}
|
|
2544
2597
|
if (requiredFieldNames.size > 0) {
|
|
@@ -2577,25 +2630,6 @@ class NormalizationFactory {
|
|
|
2577
2630
|
}
|
|
2578
2631
|
definitions.push(...dependencies);
|
|
2579
2632
|
}
|
|
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
2633
|
normalize(document) {
|
|
2600
2634
|
// Collect any renamed root types
|
|
2601
2635
|
(0, walkers_1.upsertDirectiveSchemaAndEntityDefinitions)(this, document);
|
|
@@ -2603,7 +2637,15 @@ class NormalizationFactory {
|
|
|
2603
2637
|
const definitions = [];
|
|
2604
2638
|
this.#addDirectiveDefinitionsToDocument(definitions);
|
|
2605
2639
|
this.validateDirectives(this.schemaData, string_constants_1.SCHEMA);
|
|
2606
|
-
const schemaNode = this
|
|
2640
|
+
const schemaNode = this.getSchemaNodeByData(this.schemaData);
|
|
2641
|
+
/* Schema extension orphans are not supported on old routers.
|
|
2642
|
+
* Consequently, it is a breaking change that requires a new composition version, and hat composition version
|
|
2643
|
+
* would only be compatible with newer routers that support schema extension orphans.
|
|
2644
|
+
* For now, only a valid schema definition node is pushed.
|
|
2645
|
+
*/
|
|
2646
|
+
if (schemaNode?.kind === graphql_1.Kind.SCHEMA_DEFINITION) {
|
|
2647
|
+
definitions.push(schemaNode);
|
|
2648
|
+
}
|
|
2607
2649
|
for (const [parentTypeName, parentData] of this.parentDefinitionDataByTypeName) {
|
|
2608
2650
|
this.validateDirectives(parentData, parentTypeName);
|
|
2609
2651
|
}
|
|
@@ -2739,7 +2781,10 @@ class NormalizationFactory {
|
|
|
2739
2781
|
this.addFieldNamesToConfigurationData(parentData.fieldDataByName, configurationData);
|
|
2740
2782
|
this.validateInterfaceImplementations(parentData);
|
|
2741
2783
|
definitions.push(this.getCompositeOutputNodeByData(parentData));
|
|
2742
|
-
|
|
2784
|
+
/* Interfaces and Objects must define at least one field.
|
|
2785
|
+
* However, some servers allow a query root type to be defined without fields.
|
|
2786
|
+
* This is so it can be renamed and any federation boiler plate is appended to that renamed node.
|
|
2787
|
+
* */
|
|
2743
2788
|
if (parentData.fieldDataByName.size < 1 && !(0, utils_2.isNodeQuery)(parentTypeName, operationTypeNode)) {
|
|
2744
2789
|
this.errors.push((0, errors_1.noFieldDefinitionsError)((0, utils_5.kindToNodeType)(parentData.kind), parentTypeName));
|
|
2745
2790
|
}
|