@wundergraph/composition 0.63.0 → 0.63.1
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/params.d.ts +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/results.d.ts +1 -0
- package/dist/utils/composition-version.js +1 -1
- package/dist/v1/normalization/normalization-factory.d.ts +2 -1
- package/dist/v1/normalization/normalization-factory.js +112 -7
- package/dist/v1/normalization/normalization-factory.js.map +1 -1
- package/dist/v1/normalization/types/params.d.ts +9 -0
- package/dist/v1/warnings/params.d.ts +8 -1
- package/dist/v1/warnings/warnings.d.ts +3 -2
- package/dist/v1/warnings/warnings.js +15 -2
- package/dist/v1/warnings/warnings.js.map +1 -1
- package/package.json +2 -2
package/dist/types/results.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export interface ExecutionSingleFailure extends ExecutionFailure {
|
|
|
10
10
|
export interface ExecutionSuccess {
|
|
11
11
|
success: true;
|
|
12
12
|
}
|
|
13
|
+
export type ExecutionResult = ExecutionFailure | ExecutionSuccess;
|
|
13
14
|
export type ExecutionMultiResult = ExecutionMultiFailure | ExecutionSuccess;
|
|
14
15
|
export type ExecutionSingleFailureResult = ExecutionSingleFailure | ExecutionSuccess;
|
|
@@ -9,7 +9,7 @@ import { type Warning } from '../../warnings/types';
|
|
|
9
9
|
import { type NormalizationResult } from '../../normalization/types';
|
|
10
10
|
import { type AddInputValueDataByNodeParams, type ComposeDirectiveNode, type ConditionalFieldSetValidationResult, type ExtractDirectiveArgumentDataResult, type FieldSetData, type HandleCostDirectiveParams, type HandleListSizeDirectiveParams, type HandleOverrideDirectiveParams, type HandleRequiresScopesDirectiveParams, type HandleSemanticNonNullDirectiveParams, type KeyFieldSetData, type LinkImportData, type RecordDirectiveWeightOnFieldParams, type UpsertInputObjectResult, type ValidateDirectiveParams } from './types/types';
|
|
11
11
|
import { type AbstractTypeName, type ArgumentName, type DirectiveName, type FieldName, type SubgraphName, type TypeName } from '../../types/types';
|
|
12
|
-
import { type GetFieldSetParentParams, type HandleFieldInheritableDirectivesParams, type NormalizationFactoryParams, type NormalizeSubgraphFromStringParams, type NormalizeSubgraphParams, type ValidateOneOfDirectiveParams } from './types/params';
|
|
12
|
+
import { type GetFieldSetParentParams, type HandleFieldInheritableDirectivesParams, type IsAnyImplementationFieldExternalParams, type NormalizationFactoryParams, type NormalizeSubgraphFromStringParams, type NormalizeSubgraphParams, type ValidateOneOfDirectiveParams } from './types/params';
|
|
13
13
|
import type { CompositionOptions } from '../../types/params';
|
|
14
14
|
import { type FieldSetParentResult, type SchemaNodeResult } from './types/results';
|
|
15
15
|
import { type AddDirectiveArgumentDataByNodeParams, type ExtractDirectiveArgumentDataParams } from '../../directive-definition-data/types/params';
|
|
@@ -102,6 +102,7 @@ export declare class NormalizationFactory {
|
|
|
102
102
|
upsertUnionByNode(node: UnionTypeNode, isRealExtension?: boolean): void;
|
|
103
103
|
extractKeyFieldSets(node: CompositeOutputNode, keyFieldSetDataByFieldSet: Map<string, KeyFieldSetData>): void;
|
|
104
104
|
getFieldSetParent({ isProvides, parentData, fieldName, fieldSet, parentTypeName, }: GetFieldSetParentParams): FieldSetParentResult;
|
|
105
|
+
handleConditionalImplementationField({ fieldCoordsPath, fieldName, fieldPath, interfaceTypeName, isProvides, }: IsAnyImplementationFieldExternalParams): boolean;
|
|
105
106
|
validateConditionalFieldSet(selectionSetParentData: CompositeOutputData | UnionDefinitionData, fieldSet: string, directiveFieldName: string, isProvides: boolean, directiveParentTypeName: string): ConditionalFieldSetValidationResult;
|
|
106
107
|
validateProvidesOrRequires(parentData: CompositeOutputData, fieldSetByFieldName: Map<string, string>, isProvides: boolean): RequiredFieldConfiguration[] | undefined;
|
|
107
108
|
validateInterfaceImplementations(data: CompositeOutputData): void;
|
|
@@ -1185,7 +1185,7 @@ class NormalizationFactory {
|
|
|
1185
1185
|
if ((0, utils_1.isValidProvidesParentData)(namedTypeData)) {
|
|
1186
1186
|
if ((0, utils_3.isUnionDefinitionData)(namedTypeData)) {
|
|
1187
1187
|
this.warnings.push((0, warnings_1.providesOnUnionWarning)({
|
|
1188
|
-
fieldCoords,
|
|
1188
|
+
directiveCoords: fieldCoords,
|
|
1189
1189
|
fieldSet,
|
|
1190
1190
|
namedTypeName: fieldNamedTypeName,
|
|
1191
1191
|
subgraphName: this.subgraphName,
|
|
@@ -1205,7 +1205,18 @@ class NormalizationFactory {
|
|
|
1205
1205
|
success: false,
|
|
1206
1206
|
};
|
|
1207
1207
|
}
|
|
1208
|
-
#handleNonExternalConditionalField({ currentFieldCoords, directiveCoords, directiveName, fieldSet, }) {
|
|
1208
|
+
#handleNonExternalConditionalField({ currentFieldCoords, directiveCoords, directiveName, fieldSet, parentData, selection, }) {
|
|
1209
|
+
if ((0, utils_4.isInterfaceDefinitionData)(parentData)) {
|
|
1210
|
+
this.errors.push((0, errors_1.directlyProvidedInterfaceFieldError)({
|
|
1211
|
+
directiveCoords,
|
|
1212
|
+
directiveName,
|
|
1213
|
+
fieldSet,
|
|
1214
|
+
selection,
|
|
1215
|
+
subgraphName: this.subgraphName,
|
|
1216
|
+
targetCoords: currentFieldCoords,
|
|
1217
|
+
}));
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1209
1220
|
if (this.isSubgraphVersionTwo) {
|
|
1210
1221
|
this.errors.push((0, errors_1.nonExternalConditionalFieldError)({
|
|
1211
1222
|
directiveCoords,
|
|
@@ -1221,6 +1232,37 @@ class NormalizationFactory {
|
|
|
1221
1232
|
* */
|
|
1222
1233
|
this.warnings.push((0, warnings_1.nonExternalConditionalFieldWarning)(directiveCoords, this.subgraphName, currentFieldCoords, fieldSet, directiveName));
|
|
1223
1234
|
}
|
|
1235
|
+
// Returns true if at least one implementation field is @external
|
|
1236
|
+
handleConditionalImplementationField({ fieldCoordsPath, fieldName, fieldPath, interfaceTypeName, isProvides, }) {
|
|
1237
|
+
const implementationTypeNames = this.concreteTypeNamesByAbstractTypeName.get(interfaceTypeName);
|
|
1238
|
+
if (!implementationTypeNames) {
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
let hasExternalField = false;
|
|
1242
|
+
for (const typeName of implementationTypeNames) {
|
|
1243
|
+
const data = this.parentDefinitionDataByTypeName.get(typeName);
|
|
1244
|
+
if (!(0, utils_3.isObjectDefinitionData)(data)) {
|
|
1245
|
+
continue;
|
|
1246
|
+
}
|
|
1247
|
+
const fieldData = data.fieldDataByName.get(fieldName);
|
|
1248
|
+
if (!fieldData?.directivesByName.has(string_constants_1.EXTERNAL)) {
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
const externalData = fieldData.externalFieldDataBySubgraphName.get(this.subgraphName);
|
|
1252
|
+
if (!externalData || externalData.isUnconditionallyProvided) {
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
if (!isProvides) {
|
|
1256
|
+
return true;
|
|
1257
|
+
}
|
|
1258
|
+
(0, utils_5.getValueOrDefault)(this.conditionalFieldDataByCoords, `${typeName}.${fieldName}`, utils_4.newConditionalFieldData).providedBy.push((0, utils_6.newFieldSetConditionData)({
|
|
1259
|
+
fieldCoordinatesPath: [...fieldCoordsPath],
|
|
1260
|
+
fieldPath: [...fieldPath],
|
|
1261
|
+
}));
|
|
1262
|
+
hasExternalField = true;
|
|
1263
|
+
}
|
|
1264
|
+
return hasExternalField;
|
|
1265
|
+
}
|
|
1224
1266
|
validateConditionalFieldSet(selectionSetParentData, fieldSet, directiveFieldName, isProvides, directiveParentTypeName) {
|
|
1225
1267
|
// Create a new selection set so that the value can be parsed as a new DocumentNode
|
|
1226
1268
|
const { error, documentNode } = (0, utils_1.safeParse)('{' + fieldSet + '}');
|
|
@@ -1265,17 +1307,29 @@ class NormalizationFactory {
|
|
|
1265
1307
|
fieldCoordsPath.push(currentFieldCoords);
|
|
1266
1308
|
fieldPath.push(fieldName);
|
|
1267
1309
|
lastFieldName = fieldName;
|
|
1310
|
+
const isInterfaceParent = (0, utils_4.isInterfaceDefinitionData)(parentData);
|
|
1268
1311
|
if (fieldName === string_constants_1.TYPENAME) {
|
|
1269
1312
|
if (isProvides) {
|
|
1270
1313
|
errorMessages.push((0, errors_1.typeNameAlreadyProvidedErrorMessage)(currentFieldCoords, nf.subgraphName));
|
|
1271
1314
|
return graphql_1.BREAK;
|
|
1272
1315
|
}
|
|
1273
1316
|
if (externalAncestors.size < 1) {
|
|
1317
|
+
if (isProvides && isInterfaceParent) {
|
|
1318
|
+
nf.warnings.push((0, warnings_1.providesWithInterfaceFieldSelectionWarning)({
|
|
1319
|
+
directiveCoords,
|
|
1320
|
+
fieldCoords: currentFieldCoords,
|
|
1321
|
+
fieldSet,
|
|
1322
|
+
selection: fieldPath.length < 2 ? fieldName : `${fieldPath.at(-2)} { ${fieldName} }`,
|
|
1323
|
+
subgraphName: nf.subgraphName,
|
|
1324
|
+
}));
|
|
1325
|
+
}
|
|
1274
1326
|
nf.#handleNonExternalConditionalField({
|
|
1275
1327
|
currentFieldCoords,
|
|
1276
1328
|
directiveCoords,
|
|
1277
1329
|
directiveName,
|
|
1278
1330
|
fieldSet,
|
|
1331
|
+
parentData,
|
|
1332
|
+
selection: fieldPath.length < 2 ? fieldName : `${fieldPath.at(-2)} { ${fieldName} }`,
|
|
1279
1333
|
});
|
|
1280
1334
|
}
|
|
1281
1335
|
return;
|
|
@@ -1304,14 +1358,43 @@ class NormalizationFactory {
|
|
|
1304
1358
|
namedTypeData?.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION ||
|
|
1305
1359
|
namedTypeData?.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
|
1306
1360
|
if (externalAncestors.size < 1 && !isDefinedExternal) {
|
|
1361
|
+
if (isProvides && isInterfaceParent) {
|
|
1362
|
+
nf.warnings.push((0, warnings_1.providesWithInterfaceFieldSelectionWarning)({
|
|
1363
|
+
directiveCoords,
|
|
1364
|
+
fieldCoords: currentFieldCoords,
|
|
1365
|
+
fieldSet,
|
|
1366
|
+
selection: fieldPath.length < 2 ? fieldName : `${fieldPath.at(-2)} { ${fieldName} }`,
|
|
1367
|
+
subgraphName: nf.subgraphName,
|
|
1368
|
+
}));
|
|
1369
|
+
}
|
|
1307
1370
|
nf.#handleNonExternalConditionalField({
|
|
1308
1371
|
currentFieldCoords,
|
|
1309
1372
|
directiveCoords,
|
|
1310
1373
|
directiveName,
|
|
1311
1374
|
fieldSet,
|
|
1375
|
+
parentData,
|
|
1376
|
+
selection: fieldPath.length < 2 ? fieldName : `${fieldPath.at(-2)} { ${fieldName} }`,
|
|
1312
1377
|
});
|
|
1313
1378
|
return;
|
|
1314
1379
|
}
|
|
1380
|
+
if (isInterfaceParent) {
|
|
1381
|
+
if (isProvides) {
|
|
1382
|
+
nf.warnings.push((0, warnings_1.providesWithInterfaceFieldSelectionWarning)({
|
|
1383
|
+
directiveCoords,
|
|
1384
|
+
fieldCoords: currentFieldCoords,
|
|
1385
|
+
fieldSet,
|
|
1386
|
+
selection: fieldPath.length < 2 ? fieldName : `${fieldPath.at(-2)} { ${fieldName} }`,
|
|
1387
|
+
subgraphName: nf.subgraphName,
|
|
1388
|
+
}));
|
|
1389
|
+
}
|
|
1390
|
+
nf.handleConditionalImplementationField({
|
|
1391
|
+
fieldCoordsPath,
|
|
1392
|
+
fieldName,
|
|
1393
|
+
fieldPath,
|
|
1394
|
+
interfaceTypeName: parentData.name,
|
|
1395
|
+
isProvides,
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1315
1398
|
if (externalAncestors.size < 1 && isUnconditionallyProvided) {
|
|
1316
1399
|
// V2 subgraphs return an error when an external key field on an entity extension is provided.
|
|
1317
1400
|
if (nf.isSubgraphVersionTwo) {
|
|
@@ -1352,13 +1435,35 @@ class NormalizationFactory {
|
|
|
1352
1435
|
}
|
|
1353
1436
|
externalAncestors.add(currentFieldCoords);
|
|
1354
1437
|
}
|
|
1355
|
-
if (
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1438
|
+
if (!(0, utils_1.isValidProvidesParentData)(namedTypeData)) {
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
shouldDefineSelectionSet = true;
|
|
1442
|
+
parentDatas.push(namedTypeData);
|
|
1443
|
+
if (!isInterfaceParent) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
if (isProvides) {
|
|
1447
|
+
nf.warnings.push((0, warnings_1.providesWithInterfaceFieldSelectionWarning)({
|
|
1448
|
+
directiveCoords,
|
|
1449
|
+
fieldCoords: currentFieldCoords,
|
|
1450
|
+
fieldSet,
|
|
1451
|
+
selection: fieldPath.length < 2 ? fieldName : `${fieldPath.at(-2)} { ${fieldName} }`,
|
|
1452
|
+
subgraphName: nf.subgraphName,
|
|
1453
|
+
}));
|
|
1454
|
+
}
|
|
1455
|
+
if (!nf.handleConditionalImplementationField({
|
|
1456
|
+
fieldCoordsPath,
|
|
1457
|
+
fieldName,
|
|
1458
|
+
fieldPath,
|
|
1459
|
+
interfaceTypeName: parentData.name,
|
|
1460
|
+
isProvides,
|
|
1461
|
+
}) ||
|
|
1462
|
+
externalAncestors.size > 0) {
|
|
1360
1463
|
return;
|
|
1361
1464
|
}
|
|
1465
|
+
hasConditionalField = true;
|
|
1466
|
+
externalAncestors.add(currentFieldCoords);
|
|
1362
1467
|
},
|
|
1363
1468
|
leave() {
|
|
1364
1469
|
externalAncestors.delete(fieldCoordsPath.pop() || '');
|