@wundergraph/composition 0.52.0 → 0.54.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/README.md +6 -0
- package/dist/ast/utils.d.ts +2 -2
- package/dist/buildASTSchema/buildASTSchema.d.ts +2 -2
- package/dist/buildASTSchema/buildASTSchema.js.map +1 -1
- package/dist/buildASTSchema/extendSchema.d.ts +3 -3
- package/dist/errors/errors.d.ts +17 -7
- package/dist/errors/errors.js +50 -0
- package/dist/errors/errors.js.map +1 -1
- package/dist/errors/types.d.ts +2 -2
- package/dist/federation/federation.d.ts +5 -4
- package/dist/federation/federation.js +6 -6
- package/dist/federation/federation.js.map +1 -1
- package/dist/federation/params.d.ts +22 -0
- package/dist/{v1/federation/types.js → federation/params.js} +1 -1
- package/dist/federation/params.js.map +1 -0
- package/dist/federation/types.d.ts +6 -24
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/normalization/normalization.d.ts +5 -8
- package/dist/normalization/normalization.js +6 -6
- package/dist/normalization/normalization.js.map +1 -1
- package/dist/normalization/params.d.ts +24 -0
- package/dist/normalization/params.js +3 -0
- package/dist/normalization/params.js.map +1 -0
- package/dist/normalization/types.d.ts +8 -7
- package/dist/resolvability-graph/graph-nodes.d.ts +2 -2
- package/dist/resolvability-graph/graph.d.ts +6 -6
- package/dist/resolvability-graph/graph.js.map +1 -1
- package/dist/resolvability-graph/node-resolution-data/node-resolution-data.d.ts +3 -3
- package/dist/resolvability-graph/node-resolution-data/types/params.d.ts +2 -2
- package/dist/resolvability-graph/types/params.d.ts +2 -2
- package/dist/resolvability-graph/utils/types/params.d.ts +4 -4
- package/dist/resolvability-graph/utils/types/types.d.ts +1 -1
- package/dist/resolvability-graph/utils/utils.d.ts +4 -4
- package/dist/resolvability-graph/utils/utils.js.map +1 -1
- package/dist/resolvability-graph/walker/entity-walker/entity-walker.d.ts +1 -1
- package/dist/resolvability-graph/walker/entity-walker/types/params.d.ts +3 -3
- package/dist/resolvability-graph/walker/root-field-walkers/root-field-walker.d.ts +2 -2
- package/dist/resolvability-graph/walker/root-field-walkers/types/params.d.ts +3 -3
- package/dist/router-configuration/types.d.ts +21 -1
- package/dist/router-configuration/utils.d.ts +1 -1
- package/dist/schema-building/ast.d.ts +1 -1
- package/dist/schema-building/types.d.ts +6 -6
- package/dist/schema-building/utils.d.ts +8 -7
- package/dist/schema-building/utils.js +12 -2
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/subgraph/types.d.ts +7 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/params.d.ts +4 -0
- package/dist/types/params.js +3 -0
- package/dist/types/params.js.map +1 -0
- package/dist/types/types.d.ts +2 -0
- package/dist/utils/composition-version.js +1 -1
- package/dist/utils/string-constants.d.ts +7 -0
- package/dist/utils/string-constants.js +11 -4
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/utils/types.d.ts +2 -2
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js.map +1 -1
- package/dist/v1/constants/constants.d.ts +2 -2
- package/dist/v1/constants/constants.js +2 -0
- package/dist/v1/constants/constants.js.map +1 -1
- package/dist/v1/constants/directive-definitions.d.ts +3 -1
- package/dist/v1/constants/directive-definitions.js +77 -1
- package/dist/v1/constants/directive-definitions.js.map +1 -1
- package/dist/v1/constants/non-directive-definitions.d.ts +1 -1
- package/dist/v1/constants/non-directive-definitions.js.map +1 -1
- package/dist/v1/constants/strings.d.ts +2 -2
- package/dist/v1/constants/strings.js.map +1 -1
- package/dist/v1/constants/type-nodes.d.ts +1 -1
- package/dist/v1/constants/type-nodes.js.map +1 -1
- package/dist/v1/federation/federation-factory.d.ts +20 -20
- package/dist/v1/federation/federation-factory.js +22 -20
- package/dist/v1/federation/federation-factory.js.map +1 -1
- package/dist/v1/federation/params.d.ts +33 -3
- package/dist/v1/federation/utils.d.ts +8 -21
- package/dist/v1/federation/utils.js.map +1 -1
- package/dist/v1/federation/walkers.d.ts +2 -2
- package/dist/v1/federation/walkers.js.map +1 -1
- package/dist/v1/normalization/directive-definition-data.d.ts +3 -1
- package/dist/v1/normalization/directive-definition-data.js +82 -1
- package/dist/v1/normalization/directive-definition-data.js.map +1 -1
- package/dist/v1/normalization/normalization-factory.d.ts +21 -16
- package/dist/v1/normalization/normalization-factory.js +260 -9
- package/dist/v1/normalization/normalization-factory.js.map +1 -1
- package/dist/v1/normalization/params.d.ts +25 -2
- package/dist/v1/normalization/types.d.ts +16 -4
- package/dist/v1/normalization/utils.d.ts +5 -5
- package/dist/v1/normalization/utils.js +3 -1
- package/dist/v1/normalization/utils.js.map +1 -1
- package/dist/v1/normalization/walkers.d.ts +2 -2
- package/dist/v1/normalization/walkers.js.map +1 -1
- package/dist/v1/schema-building/type-merging.d.ts +2 -2
- package/dist/v1/schema-building/type-merging.js.map +1 -1
- package/dist/v1/utils/utils.d.ts +1 -1
- package/dist/v1/warnings/params.d.ts +1 -1
- package/dist/v1/warnings/warnings.d.ts +1 -1
- package/dist/v1/warnings/warnings.js.map +1 -1
- package/package.json +3 -3
- package/dist/v1/federation/types.d.ts +0 -17
- package/dist/v1/federation/types.js.map +0 -1
|
@@ -26,16 +26,20 @@ const integer_constants_1 = require("../../utils/integer-constants");
|
|
|
26
26
|
const utils_5 = require("../../utils/utils");
|
|
27
27
|
const utils_6 = require("../../router-configuration/utils");
|
|
28
28
|
const non_directive_definitions_1 = require("../constants/non-directive-definitions");
|
|
29
|
-
function normalizeSubgraphFromString(
|
|
30
|
-
const { error, documentNode } = (0, utils_1.safeParse)(
|
|
29
|
+
function normalizeSubgraphFromString({ noLocation, options, sdlString, }) {
|
|
30
|
+
const { error, documentNode } = (0, utils_1.safeParse)(sdlString, noLocation);
|
|
31
31
|
if (error || !documentNode) {
|
|
32
32
|
return { errors: [(0, errors_1.subgraphInvalidSyntaxError)(error)], success: false, warnings: [] };
|
|
33
33
|
}
|
|
34
|
-
const normalizationFactory = new NormalizationFactory(new graph_1.Graph());
|
|
34
|
+
const normalizationFactory = new NormalizationFactory({ internalGraph: new graph_1.Graph(), options });
|
|
35
35
|
return normalizationFactory.normalize(documentNode);
|
|
36
36
|
}
|
|
37
|
-
function normalizeSubgraph(document, subgraphName,
|
|
38
|
-
const normalizationFactory = new NormalizationFactory(
|
|
37
|
+
function normalizeSubgraph({ document, internalGraph, options, subgraphName, }) {
|
|
38
|
+
const normalizationFactory = new NormalizationFactory({
|
|
39
|
+
internalGraph: internalGraph || new graph_1.Graph(),
|
|
40
|
+
options,
|
|
41
|
+
subgraphName,
|
|
42
|
+
});
|
|
39
43
|
return normalizationFactory.normalize(document);
|
|
40
44
|
}
|
|
41
45
|
class NormalizationFactory {
|
|
@@ -44,6 +48,12 @@ class NormalizationFactory {
|
|
|
44
48
|
concreteTypeNamesByAbstractTypeName = new Map();
|
|
45
49
|
conditionalFieldDataByCoords = new Map();
|
|
46
50
|
configurationDataByTypeName = new Map();
|
|
51
|
+
costs = {
|
|
52
|
+
fieldWeights: new Map(),
|
|
53
|
+
listSizes: new Map(),
|
|
54
|
+
typeWeights: new Map(),
|
|
55
|
+
directiveArgumentWeights: new Map(),
|
|
56
|
+
};
|
|
47
57
|
customDirectiveDefinitionByName = new Map();
|
|
48
58
|
definedDirectiveNames = new Set();
|
|
49
59
|
directiveDefinitionByName = new Map();
|
|
@@ -66,6 +76,7 @@ class NormalizationFactory {
|
|
|
66
76
|
keyFieldSetDatasByTypeName = new Map();
|
|
67
77
|
lastParentNodeKind = graphql_1.Kind.NULL;
|
|
68
78
|
lastChildNodeKind = graphql_1.Kind.NULL;
|
|
79
|
+
options;
|
|
69
80
|
parentTypeNamesWithAuthDirectives = new Set();
|
|
70
81
|
keyFieldSetsByEntityTypeNameByFieldCoords = new Map();
|
|
71
82
|
keyFieldNamesByParentTypeName = new Map();
|
|
@@ -83,7 +94,8 @@ class NormalizationFactory {
|
|
|
83
94
|
unvalidatedExternalFieldCoords = new Set();
|
|
84
95
|
usesEdfsNatsStreamConfiguration = false;
|
|
85
96
|
warnings = [];
|
|
86
|
-
constructor(internalGraph, subgraphName) {
|
|
97
|
+
constructor({ internalGraph, options, subgraphName }) {
|
|
98
|
+
this.options = options ?? {};
|
|
87
99
|
this.subgraphName = subgraphName || string_constants_1.NOT_APPLICABLE;
|
|
88
100
|
this.internalGraph = internalGraph;
|
|
89
101
|
this.internalGraph.setSubgraphName(this.subgraphName);
|
|
@@ -257,7 +269,9 @@ class NormalizationFactory {
|
|
|
257
269
|
const directiveName = directiveNode.name.value;
|
|
258
270
|
const parentTypeName = data.kind === graphql_1.Kind.FIELD_DEFINITION ? data.renamedParentTypeName || data.originalParentTypeName : data.name;
|
|
259
271
|
const isAuthenticated = directiveName === string_constants_1.AUTHENTICATED;
|
|
272
|
+
const isCost = directiveName === string_constants_1.COST;
|
|
260
273
|
const isField = (0, utils_4.isFieldData)(data);
|
|
274
|
+
const isListSize = directiveName === string_constants_1.LIST_SIZE;
|
|
261
275
|
const isOverride = directiveName === string_constants_1.OVERRIDE;
|
|
262
276
|
const isRequiresScopes = directiveName === string_constants_1.REQUIRES_SCOPES;
|
|
263
277
|
const isSemanticNonNull = directiveName === string_constants_1.SEMANTIC_NON_NULL;
|
|
@@ -280,6 +294,9 @@ class NormalizationFactory {
|
|
|
280
294
|
data.nullLevelsBySubgraphName.set(this.subgraphName, new Set([0]));
|
|
281
295
|
}
|
|
282
296
|
}
|
|
297
|
+
if (isListSize && isField && !(0, utils_4.isTypeNodeListType)(data.type)) {
|
|
298
|
+
errorMessages.push((0, errors_1.listSizeFieldMustReturnListOrUseSizedFieldsErrorMessage)(directiveCoords, (0, merge_1.printTypeNode)(data.type)));
|
|
299
|
+
}
|
|
283
300
|
return errorMessages;
|
|
284
301
|
}
|
|
285
302
|
const definedArgumentNames = new Set();
|
|
@@ -333,6 +350,12 @@ class NormalizationFactory {
|
|
|
333
350
|
requiredScopes,
|
|
334
351
|
});
|
|
335
352
|
}
|
|
353
|
+
if (isCost) {
|
|
354
|
+
this.handleCostDirective({ data, directiveCoords, directiveNode, errorMessages });
|
|
355
|
+
}
|
|
356
|
+
else if (isListSize && isField) {
|
|
357
|
+
this.handleListSizeDirective({ data, directiveCoords, directiveNode, errorMessages });
|
|
358
|
+
}
|
|
336
359
|
if (duplicateArgumentNames.size > 0) {
|
|
337
360
|
errorMessages.push((0, errors_1.duplicateDirectiveArgumentDefinitionsErrorMessage)([...duplicateArgumentNames]));
|
|
338
361
|
}
|
|
@@ -652,6 +675,37 @@ class NormalizationFactory {
|
|
|
652
675
|
}
|
|
653
676
|
return output;
|
|
654
677
|
}
|
|
678
|
+
// extracts cost weights from @cost directives applied to arguments of directive definitions.
|
|
679
|
+
// It works on nodes of this kind: "directive @myDirective(arg1: Int @cost(weight: 5)) on FIELD"
|
|
680
|
+
extractDirectiveArgumentCosts(node) {
|
|
681
|
+
if (!node.arguments) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const directiveName = node.name.value;
|
|
685
|
+
for (const argNode of node.arguments) {
|
|
686
|
+
if (!argNode.directives) {
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
for (const directive of argNode.directives) {
|
|
690
|
+
if (directive.name.value !== string_constants_1.COST) {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
const weightArg = directive.arguments?.find((a) => a.name.value === string_constants_1.WEIGHT);
|
|
694
|
+
if (!weightArg) {
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
if (weightArg.value.kind !== graphql_1.Kind.INT) {
|
|
698
|
+
const directiveCoords = `@${directiveName}(${argNode.name.value}: ...)`;
|
|
699
|
+
this.errors.push((0, errors_1.invalidDirectiveError)(string_constants_1.COST, directiveCoords, '1st', [
|
|
700
|
+
(0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(weightArg.value), `@${string_constants_1.COST}`, string_constants_1.WEIGHT, 'Int!'),
|
|
701
|
+
]));
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
const weightValue = parseInt(weightArg.value.value, 10);
|
|
705
|
+
this.costs.directiveArgumentWeights.set(`${directiveName}.${argNode.name.value}`, weightValue);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
655
709
|
// returns true if the directive is custom; otherwise, false
|
|
656
710
|
addDirectiveDefinitionDataByNode(node) {
|
|
657
711
|
const name = node.name.value;
|
|
@@ -660,6 +714,7 @@ class NormalizationFactory {
|
|
|
660
714
|
return false;
|
|
661
715
|
}
|
|
662
716
|
this.definedDirectiveNames.add(name);
|
|
717
|
+
this.extractDirectiveArgumentCosts(node);
|
|
663
718
|
// Normalize federation directives by replacing them with predefined definitions
|
|
664
719
|
const definition = constants_1.V2_DIRECTIVE_DEFINITION_BY_DIRECTIVE_NAME.get(name);
|
|
665
720
|
// Add the V2 directive definitions regardless of use so the subgraph can be recognised as a V2 subgraph.
|
|
@@ -1631,6 +1686,195 @@ class NormalizationFactory {
|
|
|
1631
1686
|
}
|
|
1632
1687
|
data.nullLevelsBySubgraphName.set(this.subgraphName, levels);
|
|
1633
1688
|
}
|
|
1689
|
+
handleCostDirective({ data, directiveCoords, directiveNode, errorMessages }) {
|
|
1690
|
+
const weightArg = directiveNode.arguments?.find((arg) => arg.name.value === string_constants_1.WEIGHT);
|
|
1691
|
+
if (!weightArg || weightArg.value.kind !== graphql_1.Kind.INT) {
|
|
1692
|
+
return; // type validation handled upstream
|
|
1693
|
+
}
|
|
1694
|
+
const weightValue = parseInt(weightArg.value.value, 10);
|
|
1695
|
+
switch (data.kind) {
|
|
1696
|
+
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
1697
|
+
case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
|
|
1698
|
+
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
|
|
1699
|
+
this.costs.typeWeights.set(data.name, weightValue);
|
|
1700
|
+
break;
|
|
1701
|
+
case graphql_1.Kind.FIELD_DEFINITION: {
|
|
1702
|
+
const typeName = data.renamedParentTypeName || data.originalParentTypeName;
|
|
1703
|
+
const parentTypeData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
1704
|
+
if (!parentTypeData) {
|
|
1705
|
+
// undefined types are handled elsewhere
|
|
1706
|
+
break;
|
|
1707
|
+
}
|
|
1708
|
+
if (parentTypeData.kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
1709
|
+
errorMessages.push((0, errors_1.costOnInterfaceFieldErrorMessage)(directiveCoords));
|
|
1710
|
+
break;
|
|
1711
|
+
}
|
|
1712
|
+
const fieldCoords = `${typeName}.${data.name}`;
|
|
1713
|
+
const fieldWeight = (0, utils_5.getValueOrDefault)(this.costs.fieldWeights, fieldCoords, () => ({
|
|
1714
|
+
typeName,
|
|
1715
|
+
fieldName: data.name,
|
|
1716
|
+
argumentWeights: new Map(),
|
|
1717
|
+
}));
|
|
1718
|
+
fieldWeight.weight = weightValue;
|
|
1719
|
+
break;
|
|
1720
|
+
}
|
|
1721
|
+
case graphql_1.Kind.INPUT_VALUE_DEFINITION:
|
|
1722
|
+
case graphql_1.Kind.ARGUMENT: {
|
|
1723
|
+
const ivData = data;
|
|
1724
|
+
if (ivData.isArgument && ivData.fieldName) {
|
|
1725
|
+
const typeName = ivData.renamedParentTypeName || ivData.originalParentTypeName;
|
|
1726
|
+
const parentTypeData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
1727
|
+
if (!parentTypeData) {
|
|
1728
|
+
// undefined types are handled elsewhere
|
|
1729
|
+
break;
|
|
1730
|
+
}
|
|
1731
|
+
if (parentTypeData.kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
1732
|
+
errorMessages.push((0, errors_1.costOnInterfaceFieldErrorMessage)(directiveCoords));
|
|
1733
|
+
break;
|
|
1734
|
+
}
|
|
1735
|
+
const parentFieldCoords = `${typeName}.${ivData.fieldName}`;
|
|
1736
|
+
const fieldWeight = (0, utils_5.getValueOrDefault)(this.costs.fieldWeights, parentFieldCoords, () => ({
|
|
1737
|
+
typeName,
|
|
1738
|
+
fieldName: ivData.fieldName,
|
|
1739
|
+
argumentWeights: new Map(),
|
|
1740
|
+
}));
|
|
1741
|
+
fieldWeight.argumentWeights.set(ivData.name, weightValue);
|
|
1742
|
+
}
|
|
1743
|
+
else {
|
|
1744
|
+
const typeName = ivData.renamedParentTypeName || ivData.originalParentTypeName;
|
|
1745
|
+
const fieldCoords = `${typeName}.${ivData.name}`;
|
|
1746
|
+
const fieldWeight = (0, utils_5.getValueOrDefault)(this.costs.fieldWeights, fieldCoords, () => ({
|
|
1747
|
+
typeName,
|
|
1748
|
+
fieldName: ivData.name,
|
|
1749
|
+
argumentWeights: new Map(),
|
|
1750
|
+
}));
|
|
1751
|
+
fieldWeight.weight = weightValue;
|
|
1752
|
+
}
|
|
1753
|
+
break;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
handleListSizeDirective({ data, directiveCoords, directiveNode, errorMessages }) {
|
|
1758
|
+
const args = directiveNode.arguments;
|
|
1759
|
+
if (!args) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
let hasSizedFields = false;
|
|
1763
|
+
const typeName = data.renamedParentTypeName || data.originalParentTypeName;
|
|
1764
|
+
const listSizeConfig = {
|
|
1765
|
+
typeName,
|
|
1766
|
+
fieldName: data.name,
|
|
1767
|
+
slicingArguments: [],
|
|
1768
|
+
sizedFields: [],
|
|
1769
|
+
requireOneSlicingArgument: true, // per IBM cost spec
|
|
1770
|
+
};
|
|
1771
|
+
for (const argumentNode of args) {
|
|
1772
|
+
const argumentName = argumentNode.name.value;
|
|
1773
|
+
// type validation handled upstream
|
|
1774
|
+
switch (argumentName) {
|
|
1775
|
+
case string_constants_1.ASSUMED_SIZE:
|
|
1776
|
+
if (argumentNode.value.kind === graphql_1.Kind.INT) {
|
|
1777
|
+
listSizeConfig.assumedSize = parseInt(argumentNode.value.value, 10);
|
|
1778
|
+
}
|
|
1779
|
+
break;
|
|
1780
|
+
case string_constants_1.REQUIRE_ONE_SLICING_ARGUMENT:
|
|
1781
|
+
if (argumentNode.value.kind === graphql_1.Kind.BOOLEAN) {
|
|
1782
|
+
listSizeConfig.requireOneSlicingArgument = argumentNode.value.value;
|
|
1783
|
+
}
|
|
1784
|
+
break;
|
|
1785
|
+
case string_constants_1.SLICING_ARGUMENTS: {
|
|
1786
|
+
let argumentValues;
|
|
1787
|
+
if (argumentNode.value.kind === graphql_1.Kind.LIST) {
|
|
1788
|
+
argumentValues = argumentNode.value.values;
|
|
1789
|
+
}
|
|
1790
|
+
else if (argumentNode.value.kind === graphql_1.Kind.STRING) {
|
|
1791
|
+
argumentValues = [argumentNode.value];
|
|
1792
|
+
}
|
|
1793
|
+
else {
|
|
1794
|
+
continue;
|
|
1795
|
+
}
|
|
1796
|
+
for (const valueNode of argumentValues) {
|
|
1797
|
+
if (valueNode.kind !== graphql_1.Kind.STRING) {
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
const slicingArgName = valueNode.value;
|
|
1801
|
+
const argData = data.argumentDataByName.get(slicingArgName);
|
|
1802
|
+
if (!argData) {
|
|
1803
|
+
errorMessages.push((0, errors_1.listSizeInvalidSlicingArgumentErrorMessage)(directiveCoords, slicingArgName));
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
const unwrappedType = argData.type.kind === graphql_1.Kind.NON_NULL_TYPE ? argData.type.type : argData.type;
|
|
1807
|
+
if (unwrappedType.kind === graphql_1.Kind.LIST_TYPE || argData.namedTypeName !== string_constants_1.INT_SCALAR) {
|
|
1808
|
+
errorMessages.push((0, errors_1.listSizeSlicingArgumentNotIntErrorMessage)(directiveCoords, slicingArgName, (0, merge_1.printTypeNode)(argData.type)));
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
listSizeConfig.slicingArguments.push(slicingArgName);
|
|
1812
|
+
}
|
|
1813
|
+
break;
|
|
1814
|
+
}
|
|
1815
|
+
case string_constants_1.SIZED_FIELDS: {
|
|
1816
|
+
let fieldValues;
|
|
1817
|
+
if (argumentNode.value.kind === graphql_1.Kind.LIST) {
|
|
1818
|
+
fieldValues = argumentNode.value.values;
|
|
1819
|
+
}
|
|
1820
|
+
else if (argumentNode.value.kind === graphql_1.Kind.STRING) {
|
|
1821
|
+
fieldValues = [argumentNode.value];
|
|
1822
|
+
}
|
|
1823
|
+
else {
|
|
1824
|
+
continue;
|
|
1825
|
+
}
|
|
1826
|
+
if (fieldValues.length < 1) {
|
|
1827
|
+
continue;
|
|
1828
|
+
}
|
|
1829
|
+
hasSizedFields = true;
|
|
1830
|
+
const returnTypeName = data.namedTypeName;
|
|
1831
|
+
const returnTypeData = this.parentDefinitionDataByTypeName.get(returnTypeName);
|
|
1832
|
+
if (!returnTypeData || !(0, utils_4.isParentDataCompositeOutputType)(returnTypeData)) {
|
|
1833
|
+
errorMessages.push((0, errors_1.listSizeSizedFieldsInvalidReturnTypeErrorMessage)(directiveCoords, returnTypeName));
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
for (const valueNode of fieldValues) {
|
|
1837
|
+
if (valueNode.kind !== graphql_1.Kind.STRING) {
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
const sizedFieldName = valueNode.value;
|
|
1841
|
+
const fieldData = returnTypeData.fieldDataByName.get(sizedFieldName);
|
|
1842
|
+
if (!fieldData) {
|
|
1843
|
+
errorMessages.push((0, errors_1.listSizeSizedFieldNotFoundErrorMessage)(directiveCoords, sizedFieldName, returnTypeName));
|
|
1844
|
+
continue;
|
|
1845
|
+
}
|
|
1846
|
+
if (!(0, utils_4.isTypeNodeListType)(fieldData.type)) {
|
|
1847
|
+
errorMessages.push((0, errors_1.listSizeSizedFieldNotListErrorMessage)(directiveCoords, sizedFieldName, returnTypeName, (0, merge_1.printTypeNode)(fieldData.type)));
|
|
1848
|
+
continue;
|
|
1849
|
+
}
|
|
1850
|
+
listSizeConfig.sizedFields.push(sizedFieldName);
|
|
1851
|
+
}
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
if (!hasSizedFields && !(0, utils_4.isTypeNodeListType)(data.type)) {
|
|
1857
|
+
errorMessages.push((0, errors_1.listSizeFieldMustReturnListOrUseSizedFieldsErrorMessage)(directiveCoords, (0, merge_1.printTypeNode)(data.type)));
|
|
1858
|
+
}
|
|
1859
|
+
if (hasSizedFields && (0, utils_4.isTypeNodeListType)(data.type)) {
|
|
1860
|
+
errorMessages.push((0, errors_1.listSizeSizedFieldsOnListsErrorMessage)(directiveCoords, (0, merge_1.printTypeNode)(data.type)));
|
|
1861
|
+
}
|
|
1862
|
+
if (listSizeConfig.assumedSize !== undefined && listSizeConfig.slicingArguments.length > 0) {
|
|
1863
|
+
if (listSizeConfig.requireOneSlicingArgument) {
|
|
1864
|
+
errorMessages.push((0, errors_1.listSizeAssumedSizeWithRequiredSlicingArgumentErrorMessage)(directiveCoords));
|
|
1865
|
+
}
|
|
1866
|
+
else {
|
|
1867
|
+
for (const slicingArgName of listSizeConfig.slicingArguments) {
|
|
1868
|
+
const argData = data.argumentDataByName.get(slicingArgName);
|
|
1869
|
+
if (argData?.defaultValue) {
|
|
1870
|
+
errorMessages.push((0, errors_1.listSizeAssumedSizeSlicingArgDefaultErrorMessage)(directiveCoords, slicingArgName));
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
const fieldCoords = `${typeName}.${data.name}`;
|
|
1876
|
+
this.costs.listSizes.set(fieldCoords, listSizeConfig);
|
|
1877
|
+
}
|
|
1634
1878
|
extractRequiredScopes({ directiveCoords, orScopes, requiredScopes }) {
|
|
1635
1879
|
if (orScopes.length > constants_1.MAX_OR_SCOPES) {
|
|
1636
1880
|
this.invalidORScopesCoords.add(directiveCoords);
|
|
@@ -2639,7 +2883,7 @@ class NormalizationFactory {
|
|
|
2639
2883
|
this.validateDirectives(this.schemaData, string_constants_1.SCHEMA);
|
|
2640
2884
|
const schemaNode = this.getSchemaNodeByData(this.schemaData);
|
|
2641
2885
|
/* Schema extension orphans are not supported on old routers.
|
|
2642
|
-
* Consequently, it is a breaking change that requires a new composition version, and
|
|
2886
|
+
* Consequently, it is a breaking change that requires a new composition version, and that composition version
|
|
2643
2887
|
* would only be compatible with newer routers that support schema extension orphans.
|
|
2644
2888
|
* For now, only a valid schema definition node is pushed.
|
|
2645
2889
|
*/
|
|
@@ -2903,6 +3147,7 @@ class NormalizationFactory {
|
|
|
2903
3147
|
concreteTypeNamesByAbstractTypeName: this.concreteTypeNamesByAbstractTypeName,
|
|
2904
3148
|
conditionalFieldDataByCoordinates: this.conditionalFieldDataByCoords,
|
|
2905
3149
|
configurationDataByTypeName: this.configurationDataByTypeName,
|
|
3150
|
+
costs: this.costs,
|
|
2906
3151
|
directiveDefinitionByName: this.directiveDefinitionByName,
|
|
2907
3152
|
entityDataByTypeName: this.entityDataByTypeName,
|
|
2908
3153
|
entityInterfaces: this.entityInterfaceDataByTypeName,
|
|
@@ -2926,7 +3171,7 @@ class NormalizationFactory {
|
|
|
2926
3171
|
}
|
|
2927
3172
|
}
|
|
2928
3173
|
exports.NormalizationFactory = NormalizationFactory;
|
|
2929
|
-
function batchNormalize(subgraphs) {
|
|
3174
|
+
function batchNormalize({ options, subgraphs }) {
|
|
2930
3175
|
const authorizationDataByParentTypeName = new Map();
|
|
2931
3176
|
const concreteTypeNamesByAbstractTypeName = new Map();
|
|
2932
3177
|
const entityDataByTypeName = new Map();
|
|
@@ -2955,7 +3200,12 @@ function batchNormalize(subgraphs) {
|
|
|
2955
3200
|
if (!subgraph.name) {
|
|
2956
3201
|
invalidNameErrorMessages.push((0, errors_1.invalidSubgraphNameErrorMessage)(i, subgraphName));
|
|
2957
3202
|
}
|
|
2958
|
-
const normalizationResult = normalizeSubgraph(
|
|
3203
|
+
const normalizationResult = normalizeSubgraph({
|
|
3204
|
+
document: subgraph.definitions,
|
|
3205
|
+
internalGraph,
|
|
3206
|
+
options,
|
|
3207
|
+
subgraphName,
|
|
3208
|
+
});
|
|
2959
3209
|
if (normalizationResult.warnings.length > 0) {
|
|
2960
3210
|
warnings.push(...normalizationResult.warnings);
|
|
2961
3211
|
}
|
|
@@ -3004,6 +3254,7 @@ function batchNormalize(subgraphs) {
|
|
|
3004
3254
|
internalSubgraphBySubgraphName.set(subgraphName, {
|
|
3005
3255
|
conditionalFieldDataByCoordinates: normalizationResult.conditionalFieldDataByCoordinates,
|
|
3006
3256
|
configurationDataByTypeName: normalizationResult.configurationDataByTypeName,
|
|
3257
|
+
costs: normalizationResult.costs,
|
|
3007
3258
|
definitions: normalizationResult.subgraphAST,
|
|
3008
3259
|
directiveDefinitionByName: normalizationResult.directiveDefinitionByName,
|
|
3009
3260
|
entityInterfaces: normalizationResult.entityInterfaces,
|