@wundergraph/composition 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors/errors.d.ts +2 -1
- package/dist/errors/errors.js +9 -0
- package/dist/errors/errors.js.map +1 -1
- package/dist/errors/types.d.ts +5 -0
- package/dist/schema-building/utils.js +1 -1
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/composition-version.js +1 -1
- package/dist/utils/string-constants.d.ts +1 -0
- package/dist/utils/string-constants.js +6 -5
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/v1/federation/federation-factory.d.ts +2 -0
- package/dist/v1/federation/federation-factory.js +58 -17
- package/dist/v1/federation/federation-factory.js.map +1 -1
- package/dist/v1/federation/params.d.ts +8 -0
- package/dist/v1/federation/params.js +3 -0
- package/dist/v1/federation/params.js.map +1 -0
- package/dist/v1/normalization/directive-definition-data.d.ts +5 -4
- package/dist/v1/normalization/directive-definition-data.js +113 -104
- package/dist/v1/normalization/directive-definition-data.js.map +1 -1
- package/dist/v1/normalization/normalization-factory.d.ts +2 -0
- package/dist/v1/normalization/normalization-factory.js +51 -11
- package/dist/v1/normalization/normalization-factory.js.map +1 -1
- package/dist/v1/normalization/params.d.ts +6 -0
- package/dist/v1/normalization/params.js +3 -0
- package/dist/v1/normalization/params.js.map +1 -0
- package/dist/v1/normalization/utils.js +1 -0
- package/dist/v1/normalization/utils.js.map +1 -1
- package/dist/v1/utils/constants.d.ts +1 -0
- package/dist/v1/utils/constants.js +9 -1
- package/dist/v1/utils/constants.js.map +1 -1
- package/dist/v1/warnings/params.d.ts +10 -0
- package/dist/v1/warnings/params.js +3 -0
- package/dist/v1/warnings/params.js.map +1 -0
- package/dist/v1/warnings/warnings.d.ts +3 -0
- package/dist/v1/warnings/warnings.js +23 -0
- package/dist/v1/warnings/warnings.js.map +1 -1
- package/package.json +2 -2
|
@@ -13,6 +13,7 @@ import { ContractTagOptions, FederationResult, FederationResultWithContracts, Mu
|
|
|
13
13
|
import { GraphFieldData } from '../../utils/types';
|
|
14
14
|
import { FederateSubgraphsContractV1Params, FederateSubgraphsWithContractsV1Params, FederationParams } from './types';
|
|
15
15
|
import { FieldCoords, TypeName } from '../../types/types';
|
|
16
|
+
import { ValidateOneOfDirectiveParams } from './params';
|
|
16
17
|
export declare class FederationFactory {
|
|
17
18
|
authorizationDataByParentTypeName: Map<string, AuthorizationData>;
|
|
18
19
|
coordsByNamedTypeName: Map<string, Set<string>>;
|
|
@@ -90,6 +91,7 @@ export declare class FederationFactory {
|
|
|
90
91
|
getValidFieldArgumentNodes(fieldData: FieldData): MutableInputValueNode[];
|
|
91
92
|
getNodeWithPersistedDirectivesByFieldData(fieldData: FieldData, argumentNodes: Array<MutableInputValueNode>): MutableFieldNode;
|
|
92
93
|
validateSemanticNonNull(data: FieldData): void;
|
|
94
|
+
validateOneOfDirective({ data, inputValueNodes, requiredFieldNames }: ValidateOneOfDirectiveParams): boolean;
|
|
93
95
|
pushParentDefinitionDataToDocumentDefinitions(interfaceImplementations: InterfaceImplementationData[]): void;
|
|
94
96
|
pushNamedTypeAuthDataToFields(): void;
|
|
95
97
|
federateSubgraphData(): void;
|
|
@@ -23,6 +23,7 @@ const type_merging_1 = require("../schema-building/type-merging");
|
|
|
23
23
|
const string_constants_2 = require("../../utils/string-constants");
|
|
24
24
|
const integer_constants_1 = require("../../utils/integer-constants");
|
|
25
25
|
const utils_6 = require("../../utils/utils");
|
|
26
|
+
const warnings_1 = require("../warnings/warnings");
|
|
26
27
|
class FederationFactory {
|
|
27
28
|
authorizationDataByParentTypeName;
|
|
28
29
|
coordsByNamedTypeName = new Map();
|
|
@@ -51,6 +52,7 @@ class FederationFactory {
|
|
|
51
52
|
[string_constants_2.AUTHENTICATED, constants_1.AUTHENTICATED_DEFINITION],
|
|
52
53
|
[string_constants_2.DEPRECATED, constants_1.DEPRECATED_DEFINITION],
|
|
53
54
|
[string_constants_2.INACCESSIBLE, constants_1.INACCESSIBLE_DEFINITION],
|
|
55
|
+
[string_constants_2.ONE_OF, constants_1.ONE_OF_DEFINITION],
|
|
54
56
|
[string_constants_2.REQUIRES_SCOPES, constants_1.REQUIRES_SCOPES_DEFINITION],
|
|
55
57
|
[string_constants_2.SEMANTIC_NON_NULL, constants_1.SEMANTIC_NON_NULL_DEFINITION],
|
|
56
58
|
[string_constants_2.TAG, constants_1.TAG_DEFINITION],
|
|
@@ -1022,7 +1024,7 @@ class FederationFactory {
|
|
|
1022
1024
|
}
|
|
1023
1025
|
}
|
|
1024
1026
|
}
|
|
1025
|
-
if (interfaceDataByTypeName.size <
|
|
1027
|
+
if (interfaceDataByTypeName.size < 1 && !unionTypeName) {
|
|
1026
1028
|
this.errors.push((0, errors_1.incompatibleFederatedFieldNamedTypeError)(fieldCoordinates, subgraphNamesByNamedTypeName));
|
|
1027
1029
|
continue;
|
|
1028
1030
|
}
|
|
@@ -1360,13 +1362,32 @@ class FederationFactory {
|
|
|
1360
1362
|
}
|
|
1361
1363
|
}
|
|
1362
1364
|
}
|
|
1365
|
+
validateOneOfDirective({ data, inputValueNodes, requiredFieldNames }) {
|
|
1366
|
+
if (!data.directivesByDirectiveName.has(string_constants_2.ONE_OF)) {
|
|
1367
|
+
return true;
|
|
1368
|
+
}
|
|
1369
|
+
if (requiredFieldNames.size > 0) {
|
|
1370
|
+
this.errors.push((0, errors_1.oneOfRequiredFieldsError)({
|
|
1371
|
+
requiredFieldNames: Array.from(requiredFieldNames),
|
|
1372
|
+
typeName: data.name,
|
|
1373
|
+
}));
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
if (inputValueNodes.length === 1) {
|
|
1377
|
+
this.warnings.push((0, warnings_1.singleFederatedInputFieldOneOfWarning)({
|
|
1378
|
+
fieldName: inputValueNodes[0].name.value,
|
|
1379
|
+
typeName: data.name,
|
|
1380
|
+
}));
|
|
1381
|
+
}
|
|
1382
|
+
return true;
|
|
1383
|
+
}
|
|
1363
1384
|
pushParentDefinitionDataToDocumentDefinitions(interfaceImplementations) {
|
|
1364
1385
|
for (const [parentTypeName, parentDefinitionData] of this.parentDefinitionDataByTypeName) {
|
|
1365
1386
|
if (parentDefinitionData.extensionType !== types_1.ExtensionType.NONE) {
|
|
1366
1387
|
this.errors.push((0, errors_1.noBaseDefinitionForExtensionError)((0, utils_6.kindToNodeType)(parentDefinitionData.kind), parentTypeName));
|
|
1367
1388
|
}
|
|
1368
1389
|
switch (parentDefinitionData.kind) {
|
|
1369
|
-
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
|
|
1390
|
+
case graphql_1.Kind.ENUM_TYPE_DEFINITION: {
|
|
1370
1391
|
const enumValueNodes = [];
|
|
1371
1392
|
const clientEnumValueNodes = [];
|
|
1372
1393
|
const mergeMethod = this.getEnumValueMergeMethod(parentTypeName);
|
|
@@ -1421,11 +1442,16 @@ class FederationFactory {
|
|
|
1421
1442
|
values: clientEnumValueNodes,
|
|
1422
1443
|
});
|
|
1423
1444
|
break;
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
const
|
|
1427
|
-
const
|
|
1445
|
+
}
|
|
1446
|
+
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION: {
|
|
1447
|
+
const invalidRequiredInputs = new Array();
|
|
1448
|
+
const inputValueNodes = new Array();
|
|
1449
|
+
const clientInputValueNodes = new Array();
|
|
1450
|
+
const requiredFieldNames = new Set();
|
|
1428
1451
|
for (const [inputValueName, inputValueData] of parentDefinitionData.inputValueDataByName) {
|
|
1452
|
+
if ((0, utils_5.isTypeRequired)(inputValueData.type)) {
|
|
1453
|
+
requiredFieldNames.add(inputValueName);
|
|
1454
|
+
}
|
|
1429
1455
|
if (parentDefinitionData.subgraphNames.size === inputValueData.subgraphNames.size) {
|
|
1430
1456
|
inputValueNodes.push(this.getNodeWithPersistedDirectivesByInputValueData(inputValueData));
|
|
1431
1457
|
if ((0, utils_5.isNodeDataInaccessible)(inputValueData)) {
|
|
@@ -1448,6 +1474,13 @@ class FederationFactory {
|
|
|
1448
1474
|
this.errors.push((0, errors_1.invalidRequiredInputValueError)(string_constants_2.INPUT_OBJECT, parentTypeName, invalidRequiredInputs, false));
|
|
1449
1475
|
break;
|
|
1450
1476
|
}
|
|
1477
|
+
if (!this.validateOneOfDirective({
|
|
1478
|
+
data: parentDefinitionData,
|
|
1479
|
+
inputValueNodes,
|
|
1480
|
+
requiredFieldNames,
|
|
1481
|
+
})) {
|
|
1482
|
+
break;
|
|
1483
|
+
}
|
|
1451
1484
|
parentDefinitionData.node.fields = inputValueNodes;
|
|
1452
1485
|
this.routerDefinitions.push(this.getNodeForRouterSchemaByData(parentDefinitionData));
|
|
1453
1486
|
if ((0, utils_5.isNodeDataInaccessible)(parentDefinitionData)) {
|
|
@@ -1455,7 +1488,7 @@ class FederationFactory {
|
|
|
1455
1488
|
break;
|
|
1456
1489
|
}
|
|
1457
1490
|
if (clientInputValueNodes.length < 1) {
|
|
1458
|
-
this.errors.push((0, errors_1.allChildDefinitionsAreInaccessibleError)((0, utils_6.kindToNodeType)(parentDefinitionData.kind), parentTypeName, '
|
|
1491
|
+
this.errors.push((0, errors_1.allChildDefinitionsAreInaccessibleError)((0, utils_6.kindToNodeType)(parentDefinitionData.kind), parentTypeName, 'Input field'));
|
|
1459
1492
|
break;
|
|
1460
1493
|
}
|
|
1461
1494
|
this.clientDefinitions.push({
|
|
@@ -1464,9 +1497,10 @@ class FederationFactory {
|
|
|
1464
1497
|
fields: clientInputValueNodes,
|
|
1465
1498
|
});
|
|
1466
1499
|
break;
|
|
1500
|
+
}
|
|
1467
1501
|
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
1468
1502
|
// intentional fallthrough
|
|
1469
|
-
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
1503
|
+
case graphql_1.Kind.OBJECT_TYPE_DEFINITION: {
|
|
1470
1504
|
const fieldNodes = [];
|
|
1471
1505
|
const clientSchemaFieldNodes = [];
|
|
1472
1506
|
const graphFieldDataByFieldName = new Map();
|
|
@@ -1527,7 +1561,8 @@ class FederationFactory {
|
|
|
1527
1561
|
fields: clientSchemaFieldNodes,
|
|
1528
1562
|
});
|
|
1529
1563
|
break;
|
|
1530
|
-
|
|
1564
|
+
}
|
|
1565
|
+
case graphql_1.Kind.SCALAR_TYPE_DEFINITION: {
|
|
1531
1566
|
if (constants_1.BASE_SCALARS.has(parentTypeName)) {
|
|
1532
1567
|
break;
|
|
1533
1568
|
}
|
|
@@ -1543,7 +1578,8 @@ class FederationFactory {
|
|
|
1543
1578
|
directives: (0, utils_5.getClientPersistedDirectiveNodes)(parentDefinitionData),
|
|
1544
1579
|
});
|
|
1545
1580
|
break;
|
|
1546
|
-
|
|
1581
|
+
}
|
|
1582
|
+
case graphql_1.Kind.UNION_TYPE_DEFINITION: {
|
|
1547
1583
|
parentDefinitionData.node.types = (0, utils_3.mapToArrayOfValues)(parentDefinitionData.memberByMemberTypeName);
|
|
1548
1584
|
this.routerDefinitions.push(this.getNodeForRouterSchemaByData(parentDefinitionData));
|
|
1549
1585
|
if ((0, utils_5.isNodeDataInaccessible)(parentDefinitionData)) {
|
|
@@ -1562,6 +1598,7 @@ class FederationFactory {
|
|
|
1562
1598
|
types: clientMembers,
|
|
1563
1599
|
});
|
|
1564
1600
|
break;
|
|
1601
|
+
}
|
|
1565
1602
|
}
|
|
1566
1603
|
}
|
|
1567
1604
|
}
|
|
@@ -2136,15 +2173,18 @@ class FederationFactory {
|
|
|
2136
2173
|
switch (parentDefinitionData.kind) {
|
|
2137
2174
|
case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
|
|
2138
2175
|
// intentional fallthrough
|
|
2139
|
-
case graphql_1.Kind.UNION_TYPE_DEFINITION:
|
|
2140
|
-
|
|
2141
|
-
|
|
2176
|
+
case graphql_1.Kind.UNION_TYPE_DEFINITION: {
|
|
2177
|
+
break;
|
|
2178
|
+
}
|
|
2179
|
+
case graphql_1.Kind.ENUM_TYPE_DEFINITION: {
|
|
2142
2180
|
this.handleChildTagExclusions(parentDefinitionData, parentDefinitionData.enumValueDataByValueName, parentTagData.childTagDataByChildName, contractTagOptions.tagNamesToExclude);
|
|
2143
2181
|
break;
|
|
2144
|
-
|
|
2182
|
+
}
|
|
2183
|
+
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION: {
|
|
2145
2184
|
this.handleChildTagExclusions(parentDefinitionData, parentDefinitionData.inputValueDataByName, parentTagData.childTagDataByChildName, contractTagOptions.tagNamesToExclude);
|
|
2146
2185
|
break;
|
|
2147
|
-
|
|
2186
|
+
}
|
|
2187
|
+
default: {
|
|
2148
2188
|
let accessibleFields = parentDefinitionData.fieldDataByName.size;
|
|
2149
2189
|
for (const [fieldName, childTagData] of parentTagData.childTagDataByChildName) {
|
|
2150
2190
|
const fieldData = (0, utils_6.getOrThrowError)(parentDefinitionData.fieldDataByName, fieldName, `${parentTypeName}.fieldDataByFieldName`);
|
|
@@ -2160,12 +2200,12 @@ class FederationFactory {
|
|
|
2160
2200
|
accessibleFields -= 1;
|
|
2161
2201
|
continue;
|
|
2162
2202
|
}
|
|
2163
|
-
for (const [argumentName,
|
|
2203
|
+
for (const [argumentName, argTagNames] of childTagData.tagNamesByArgumentName) {
|
|
2164
2204
|
const inputValueData = (0, utils_6.getOrThrowError)(fieldData.argumentDataByName, argumentName, `${fieldName}.argumentDataByArgumentName`);
|
|
2165
2205
|
if ((0, utils_5.isNodeDataInaccessible)(inputValueData)) {
|
|
2166
2206
|
continue;
|
|
2167
2207
|
}
|
|
2168
|
-
if (!
|
|
2208
|
+
if (!contractTagOptions.tagNamesToExclude.isDisjointFrom(argTagNames)) {
|
|
2169
2209
|
(0, utils_6.getValueOrDefault)(inputValueData.persistedDirectivesData.directivesByDirectiveName, string_constants_2.INACCESSIBLE, () => [(0, utils_6.generateSimpleDirective)(string_constants_2.INACCESSIBLE)]);
|
|
2170
2210
|
this.inaccessibleCoords.add(inputValueData.federatedCoords);
|
|
2171
2211
|
}
|
|
@@ -2177,6 +2217,7 @@ class FederationFactory {
|
|
|
2177
2217
|
]);
|
|
2178
2218
|
this.inaccessibleCoords.add(parentTypeName);
|
|
2179
2219
|
}
|
|
2220
|
+
}
|
|
2180
2221
|
}
|
|
2181
2222
|
}
|
|
2182
2223
|
}
|