@wundergraph/composition 0.28.3 → 0.28.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/ast/utils.d.ts +2 -3
- package/dist/ast/utils.js +0 -17
- package/dist/ast/utils.js.map +1 -1
- package/dist/errors/errors.d.ts +13 -11
- package/dist/errors/errors.js +64 -55
- package/dist/errors/errors.js.map +1 -1
- package/dist/federation/federation-factory.d.ts +2 -5
- package/dist/federation/federation-factory.js +28 -130
- package/dist/federation/federation-factory.js.map +1 -1
- package/dist/federation/utils.d.ts +4 -6
- package/dist/federation/utils.js +4 -5
- package/dist/federation/utils.js.map +1 -1
- package/dist/federation/walkers.js +3 -3
- package/dist/federation/walkers.js.map +1 -1
- package/dist/normalization/normalization-factory.d.ts +23 -13
- package/dist/normalization/normalization-factory.js +347 -218
- package/dist/normalization/normalization-factory.js.map +1 -1
- package/dist/normalization/utils.js +9 -13
- package/dist/normalization/utils.js.map +1 -1
- package/dist/normalization/walkers.js +51 -175
- package/dist/normalization/walkers.js.map +1 -1
- package/dist/schema-building/ast.d.ts +8 -8
- package/dist/schema-building/ast.js +18 -25
- package/dist/schema-building/ast.js.map +1 -1
- package/dist/schema-building/type-definition-data.d.ts +13 -2
- package/dist/schema-building/type-definition-data.js +7 -0
- package/dist/schema-building/type-definition-data.js.map +1 -1
- package/dist/schema-building/utils.d.ts +11 -23
- package/dist/schema-building/utils.js +37 -287
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/subgraph/subgraph.d.ts +0 -2
- package/dist/subgraph/subgraph.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/string-constants.d.ts +12 -7
- package/dist/utils/string-constants.js +16 -11
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js +83 -18
- package/dist/utils/utils.js.map +1 -1
- package/dist/warnings/warnings.js +2 -2
- package/dist/warnings/warnings.js.map +1 -1
- package/package.json +2 -2
|
@@ -16,6 +16,7 @@ const merge_1 = require("@graphql-tools/merge");
|
|
|
16
16
|
const subgraph_1 = require("../subgraph/subgraph");
|
|
17
17
|
const warnings_1 = require("../warnings/warnings");
|
|
18
18
|
const walkers_1 = require("./walkers");
|
|
19
|
+
const type_definition_data_1 = require("../schema-building/type-definition-data");
|
|
19
20
|
const utils_4 = require("../schema-building/utils");
|
|
20
21
|
const ast_1 = require("../schema-building/ast");
|
|
21
22
|
const graph_1 = require("../resolvability-graph/graph");
|
|
@@ -61,7 +62,6 @@ class NormalizationFactory {
|
|
|
61
62
|
operationTypeNodeByTypeName = new Map();
|
|
62
63
|
originalTypeNameByRenamedTypeName = new Map();
|
|
63
64
|
parentDefinitionDataByTypeName = new Map();
|
|
64
|
-
parentExtensionDataByTypeName = new Map();
|
|
65
65
|
originalParentTypeName = '';
|
|
66
66
|
parentsWithChildArguments = new Set();
|
|
67
67
|
overridesByTargetSubgraphName = new Map();
|
|
@@ -264,54 +264,332 @@ class NormalizationFactory {
|
|
|
264
264
|
}
|
|
265
265
|
return directivesByDirectiveName;
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
isTypeNameRootType(typeName) {
|
|
268
|
+
return string_constants_1.ROOT_TYPE_NAMES.has(typeName) || this.operationTypeNodeByTypeName.has(typeName);
|
|
269
|
+
}
|
|
270
|
+
extractDirectives(node, directivesByDirectiveName, hostPath, isArgument = false) {
|
|
271
|
+
if (!node.directives) {
|
|
272
|
+
return directivesByDirectiveName;
|
|
273
|
+
}
|
|
274
|
+
const entityKeys = new Set();
|
|
275
|
+
for (const directiveNode of node.directives) {
|
|
276
|
+
const errorMessages = (0, utils_4.getDirectiveValidationErrors)(directiveNode, node.kind, directivesByDirectiveName, this.directiveDefinitionByDirectiveName, this.handledRepeatedDirectivesByHostPath, hostPath, isArgument);
|
|
277
|
+
const directiveName = directiveNode.name.value;
|
|
278
|
+
if (errorMessages.length > 0) {
|
|
279
|
+
this.errors.push((0, errors_1.invalidDirectiveError)(directiveName, hostPath, errorMessages));
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (string_constants_1.IGNORED_PARENT_DIRECTIVES.has(directiveName)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (directiveName === string_constants_1.KEY) {
|
|
286
|
+
// The argument was validated earlier
|
|
287
|
+
const entityKey = directiveNode.arguments[0].value.value;
|
|
288
|
+
if (entityKeys.has(entityKey)) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
entityKeys.add(entityKey);
|
|
292
|
+
}
|
|
293
|
+
const existingDirectives = directivesByDirectiveName.get(directiveName);
|
|
294
|
+
existingDirectives
|
|
295
|
+
? existingDirectives.push(directiveNode)
|
|
296
|
+
: directivesByDirectiveName.set(directiveName, [directiveNode]);
|
|
297
|
+
}
|
|
298
|
+
return directivesByDirectiveName;
|
|
299
|
+
}
|
|
300
|
+
/* ExtensionType uses a trichotomy rather than a boolean because @extends is still a definition.
|
|
301
|
+
* A definition and another definition with @extends would still be an error, so it cannot be treated
|
|
302
|
+
* as a regular extension.
|
|
303
|
+
* V1 definitions with @extends need a base type.
|
|
304
|
+
*/
|
|
305
|
+
getNodeExtensionType(isRealExtension, directivesByDirectiveName, isRootType = false) {
|
|
306
|
+
// If the extend keyword is present, it's simply an extension
|
|
307
|
+
if (isRealExtension) {
|
|
308
|
+
return type_definition_data_1.ExtensionType.REAL;
|
|
309
|
+
}
|
|
310
|
+
/*
|
|
311
|
+
* @extends is not interpreted as an extension under the following circumstances:
|
|
312
|
+
* 1. It's a root type
|
|
313
|
+
* 2. It's a V2 subgraph
|
|
314
|
+
* 3. And (of course) if @extends isn't defined at all
|
|
315
|
+
*/
|
|
316
|
+
if (isRootType || this.isSubgraphVersionTwo || !directivesByDirectiveName.has(string_constants_1.EXTENDS)) {
|
|
317
|
+
return type_definition_data_1.ExtensionType.NONE;
|
|
318
|
+
}
|
|
319
|
+
// If it's a V1 subgraph and defines @extends, it is considered an extension across subgraphs
|
|
320
|
+
return type_definition_data_1.ExtensionType.EXTENDS;
|
|
321
|
+
}
|
|
322
|
+
setParentDataExtensionType(parentData, incomingExtensionType) {
|
|
323
|
+
switch (parentData.extensionType) {
|
|
324
|
+
case type_definition_data_1.ExtensionType.EXTENDS:
|
|
325
|
+
// intentional fallthrough
|
|
326
|
+
case type_definition_data_1.ExtensionType.NONE: {
|
|
327
|
+
if (incomingExtensionType === type_definition_data_1.ExtensionType.REAL) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.errors.push((0, errors_1.duplicateTypeDefinitionError)((0, utils_3.kindToTypeString)(parentData.kind), parentData.name));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
default: {
|
|
334
|
+
parentData.extensionType = incomingExtensionType;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
extractImplementedInterfaceTypeNames(node, implementedInterfaceTypeNames) {
|
|
339
|
+
if (!node.interfaces) {
|
|
340
|
+
return implementedInterfaceTypeNames;
|
|
341
|
+
}
|
|
342
|
+
const parentTypeName = node.name.value;
|
|
343
|
+
for (const implementedInterface of node.interfaces) {
|
|
344
|
+
const interfaceTypeName = implementedInterface.name.value;
|
|
345
|
+
if (implementedInterfaceTypeNames.has(interfaceTypeName)) {
|
|
346
|
+
this.errors.push((0, errors_1.duplicateImplementedInterfaceError)((0, utils_3.kindToConvertedTypeString)(node.kind), parentTypeName, interfaceTypeName));
|
|
271
347
|
continue;
|
|
272
348
|
}
|
|
273
|
-
|
|
349
|
+
implementedInterfaceTypeNames.add(interfaceTypeName);
|
|
350
|
+
}
|
|
351
|
+
return implementedInterfaceTypeNames;
|
|
352
|
+
}
|
|
353
|
+
updateCompositeOutputDataByNode(node, parentData, directivesByDirectiveName, extensionType) {
|
|
354
|
+
this.setParentDataExtensionType(parentData, extensionType);
|
|
355
|
+
this.extractImplementedInterfaceTypeNames(node, parentData.implementedInterfaceTypeNames);
|
|
356
|
+
parentData.isEntity ||= directivesByDirectiveName.has(string_constants_1.KEY);
|
|
357
|
+
parentData.isInaccessible ||= directivesByDirectiveName.has(string_constants_1.INACCESSIBLE);
|
|
358
|
+
parentData.subgraphNames.add(this.subgraphName);
|
|
359
|
+
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
360
|
+
}
|
|
361
|
+
addConcreteTypeNamesForImplementedInterfaces(interfaceTypeNames, concreteTypeName) {
|
|
362
|
+
for (const interfaceName of interfaceTypeNames) {
|
|
363
|
+
(0, utils_3.getValueOrDefault)(this.concreteTypeNamesByAbstractTypeName, interfaceName, () => new Set()).add(concreteTypeName);
|
|
364
|
+
this.internalGraph.addEdge(this.internalGraph.addOrUpdateNode(interfaceName, { isAbstract: true }), this.internalGraph.addOrUpdateNode(concreteTypeName), concreteTypeName, true);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
upsertInterfaceDataByNode(node, isRealExtension = false) {
|
|
368
|
+
const typeName = node.name.value;
|
|
369
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
370
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map(), typeName);
|
|
371
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
372
|
+
const entityInterfaceData = this.entityInterfaceDataByTypeName.get(typeName);
|
|
373
|
+
if (entityInterfaceData && node.fields) {
|
|
374
|
+
for (const fieldNode of node.fields) {
|
|
375
|
+
entityInterfaceData.interfaceFieldNames.add(fieldNode.name.value);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (parentData) {
|
|
379
|
+
if (parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
380
|
+
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
this.updateCompositeOutputDataByNode(node, parentData, directivesByDirectiveName, extensionType);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
this.parentDefinitionDataByTypeName.set(typeName, {
|
|
387
|
+
directivesByDirectiveName,
|
|
388
|
+
extensionType,
|
|
389
|
+
fieldDataByFieldName: new Map(),
|
|
390
|
+
implementedInterfaceTypeNames: this.extractImplementedInterfaceTypeNames(node, new Set()),
|
|
391
|
+
isEntity: directivesByDirectiveName.has(string_constants_1.KEY),
|
|
392
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
393
|
+
kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
|
|
394
|
+
name: typeName,
|
|
395
|
+
node: (0, ast_1.getMutableInterfaceNode)(node.name),
|
|
396
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
397
|
+
subgraphNames: new Set([this.subgraphName]),
|
|
398
|
+
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
getRenamedRootTypeName(typeName) {
|
|
402
|
+
const operationTypeNode = this.operationTypeNodeByTypeName.get(typeName);
|
|
403
|
+
if (!operationTypeNode) {
|
|
404
|
+
return typeName;
|
|
405
|
+
}
|
|
406
|
+
switch (operationTypeNode) {
|
|
407
|
+
case graphql_1.OperationTypeNode.MUTATION:
|
|
408
|
+
return string_constants_1.MUTATION;
|
|
409
|
+
case graphql_1.OperationTypeNode.SUBSCRIPTION:
|
|
410
|
+
return string_constants_1.SUBSCRIPTION;
|
|
411
|
+
default:
|
|
412
|
+
return string_constants_1.QUERY;
|
|
274
413
|
}
|
|
275
414
|
}
|
|
276
|
-
|
|
277
|
-
|
|
415
|
+
addInterfaceObjectFieldsByNode(node) {
|
|
416
|
+
const typeName = node.name.value;
|
|
417
|
+
const entityInterfaceData = this.entityInterfaceDataByTypeName.get(typeName);
|
|
418
|
+
if (!entityInterfaceData || !entityInterfaceData.isInterfaceObject || !node.fields) {
|
|
278
419
|
return;
|
|
279
420
|
}
|
|
421
|
+
for (const fieldNode of node.fields) {
|
|
422
|
+
entityInterfaceData.interfaceObjectFieldNames.add(fieldNode.name.value);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
upsertObjectDataByNode(node, isRealExtension = false) {
|
|
280
426
|
const typeName = node.name.value;
|
|
281
|
-
|
|
282
|
-
|
|
427
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
428
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map(), typeName);
|
|
429
|
+
const isRootType = this.isTypeNameRootType(typeName);
|
|
430
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName, isRootType);
|
|
431
|
+
this.addInterfaceObjectFieldsByNode(node);
|
|
432
|
+
if (parentData) {
|
|
433
|
+
if (parentData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
434
|
+
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
this.updateCompositeOutputDataByNode(node, parentData, directivesByDirectiveName, extensionType);
|
|
438
|
+
this.addConcreteTypeNamesForImplementedInterfaces(parentData.implementedInterfaceTypeNames, typeName);
|
|
283
439
|
return;
|
|
284
440
|
}
|
|
285
|
-
this.
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
441
|
+
const implementedInterfaceTypeNames = this.extractImplementedInterfaceTypeNames(node, new Set());
|
|
442
|
+
this.addConcreteTypeNamesForImplementedInterfaces(implementedInterfaceTypeNames, typeName);
|
|
443
|
+
this.parentDefinitionDataByTypeName.set(typeName, {
|
|
444
|
+
directivesByDirectiveName,
|
|
445
|
+
extensionType,
|
|
446
|
+
fieldDataByFieldName: new Map(),
|
|
447
|
+
implementedInterfaceTypeNames,
|
|
448
|
+
isEntity: directivesByDirectiveName.has(string_constants_1.KEY),
|
|
449
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
450
|
+
isRootType,
|
|
451
|
+
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
|
|
452
|
+
name: typeName,
|
|
453
|
+
node: (0, ast_1.getMutableObjectNode)(node.name),
|
|
454
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
455
|
+
renamedTypeName: this.getRenamedRootTypeName(typeName),
|
|
456
|
+
subgraphNames: new Set([this.subgraphName]),
|
|
457
|
+
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
291
458
|
});
|
|
292
459
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
460
|
+
upsertEnumDataByNode(node, isRealExtension = false) {
|
|
461
|
+
const typeName = node.name.value;
|
|
462
|
+
this.internalGraph.addOrUpdateNode(typeName, { isLeaf: true });
|
|
463
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
464
|
+
const directivesByDirectiveName = this.extractDirectivesAndAuthorization(node, parentData?.directivesByDirectiveName || new Map());
|
|
465
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
466
|
+
if (parentData) {
|
|
467
|
+
if (parentData.kind !== graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
|
468
|
+
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
this.setParentDataExtensionType(parentData, extensionType);
|
|
472
|
+
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
this.parentDefinitionDataByTypeName.set(typeName, {
|
|
476
|
+
appearances: 1,
|
|
477
|
+
directivesByDirectiveName,
|
|
478
|
+
extensionType,
|
|
479
|
+
enumValueDataByValueName: new Map(),
|
|
480
|
+
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
|
|
481
|
+
name: typeName,
|
|
482
|
+
node: (0, ast_1.getMutableEnumNode)(node.name),
|
|
483
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
484
|
+
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
upsertInputObjectByNode(node, isRealExtension = false) {
|
|
488
|
+
const typeName = node.name.value;
|
|
489
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
490
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map(), typeName);
|
|
491
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
492
|
+
if (parentData) {
|
|
493
|
+
if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
494
|
+
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
495
|
+
return;
|
|
301
496
|
}
|
|
302
|
-
|
|
303
|
-
|
|
497
|
+
this.setParentDataExtensionType(parentData, extensionType);
|
|
498
|
+
parentData.isInaccessible ||= directivesByDirectiveName.has(string_constants_1.INACCESSIBLE);
|
|
499
|
+
parentData.subgraphNames.add(this.subgraphName);
|
|
500
|
+
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
304
501
|
return;
|
|
305
502
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
503
|
+
this.parentDefinitionDataByTypeName.set(typeName, {
|
|
504
|
+
directivesByDirectiveName,
|
|
505
|
+
extensionType,
|
|
506
|
+
inputValueDataByValueName: new Map(),
|
|
507
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
508
|
+
kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
509
|
+
name: typeName,
|
|
510
|
+
node: (0, ast_1.getMutableInputObjectNode)(node.name),
|
|
511
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
512
|
+
subgraphNames: new Set([this.subgraphName]),
|
|
513
|
+
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
upsertScalarByNode(node, isRealExtension = false) {
|
|
517
|
+
const typeName = node.name.value;
|
|
518
|
+
this.internalGraph.addOrUpdateNode(typeName, { isLeaf: true });
|
|
519
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
520
|
+
const directivesByDirectiveName = this.extractDirectivesAndAuthorization(node, parentData?.directivesByDirectiveName || new Map());
|
|
521
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
522
|
+
if (parentData) {
|
|
523
|
+
if (parentData.kind !== graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
|
|
524
|
+
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
this.setParentDataExtensionType(parentData, extensionType);
|
|
528
|
+
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
310
529
|
return;
|
|
311
530
|
}
|
|
312
|
-
|
|
313
|
-
|
|
531
|
+
this.parentDefinitionDataByTypeName.set(typeName, {
|
|
532
|
+
directivesByDirectiveName,
|
|
533
|
+
extensionType,
|
|
534
|
+
kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
|
|
535
|
+
name: typeName,
|
|
536
|
+
node: (0, ast_1.getMutableScalarNode)(node.name),
|
|
537
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
538
|
+
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
extractUnionMembers(node, membersByMemberTypeName) {
|
|
542
|
+
if (!node.types) {
|
|
543
|
+
return membersByMemberTypeName;
|
|
314
544
|
}
|
|
545
|
+
const unionTypeName = node.name.value;
|
|
546
|
+
for (const member of node.types) {
|
|
547
|
+
const memberTypeName = member.name.value;
|
|
548
|
+
if (membersByMemberTypeName.has(memberTypeName)) {
|
|
549
|
+
this.errors.push((0, errors_1.duplicateUnionMemberDefinitionError)(unionTypeName, memberTypeName));
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
(0, utils_3.getValueOrDefault)(this.concreteTypeNamesByAbstractTypeName, unionTypeName, () => new Set()).add(memberTypeName);
|
|
553
|
+
/*
|
|
554
|
+
* Scalars are never valid Union member types.
|
|
555
|
+
* However, base scalars are not upserted to the type definition data.
|
|
556
|
+
* Consequently, reference checks would yield unknown type errors in addition to invalid member errors.
|
|
557
|
+
* This check prevents error doubling were a Union member a base Scalar.
|
|
558
|
+
* */
|
|
559
|
+
if (!constants_1.BASE_SCALARS.has(memberTypeName)) {
|
|
560
|
+
this.referencedTypeNames.add(memberTypeName);
|
|
561
|
+
}
|
|
562
|
+
membersByMemberTypeName.set(memberTypeName, member);
|
|
563
|
+
}
|
|
564
|
+
return membersByMemberTypeName;
|
|
565
|
+
}
|
|
566
|
+
upsertUnionByNode(node, isRealExtension = false) {
|
|
567
|
+
const typeName = node.name.value;
|
|
568
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
569
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map(), typeName);
|
|
570
|
+
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
571
|
+
// Also adds the concrete type name edges to the internal graph
|
|
572
|
+
this.addConcreteTypeNamesForUnion(node);
|
|
573
|
+
if (parentData) {
|
|
574
|
+
if (parentData.kind !== graphql_1.Kind.UNION_TYPE_DEFINITION) {
|
|
575
|
+
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
this.setParentDataExtensionType(parentData, extensionType);
|
|
579
|
+
this.extractUnionMembers(node, parentData.memberByMemberTypeName);
|
|
580
|
+
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
this.parentDefinitionDataByTypeName.set(typeName, {
|
|
584
|
+
directivesByDirectiveName,
|
|
585
|
+
extensionType,
|
|
586
|
+
kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
|
|
587
|
+
memberByMemberTypeName: this.extractUnionMembers(node, new Map()),
|
|
588
|
+
name: typeName,
|
|
589
|
+
node: (0, ast_1.getMutableUnionNode)(node.name),
|
|
590
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
591
|
+
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
592
|
+
});
|
|
315
593
|
}
|
|
316
594
|
extractKeyFieldSets(node, keyFieldSetData) {
|
|
317
595
|
const isUnresolvableByRawKeyFieldSet = keyFieldSetData.isUnresolvableByKeyFieldSet;
|
|
@@ -871,23 +1149,6 @@ class NormalizationFactory {
|
|
|
871
1149
|
const nonKeyFieldNameByFieldPath = new Map();
|
|
872
1150
|
const nonEntityExtensionTypeNames = new Set();
|
|
873
1151
|
const invalidObjectTypeNames = new Set();
|
|
874
|
-
for (const [typeName, data] of this.parentExtensionDataByTypeName) {
|
|
875
|
-
if (data.kind !== graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
|
|
876
|
-
continue;
|
|
877
|
-
}
|
|
878
|
-
// If a required events directive is returned, the parent type is a root type
|
|
879
|
-
if (data.isRootType) {
|
|
880
|
-
this.validateEventDrivenRootType(data, invalidEventsDirectiveDataByRootFieldPath, invalidResponseTypeStringByRootFieldPath, invalidResponseTypeNameByMutationPath);
|
|
881
|
-
continue;
|
|
882
|
-
}
|
|
883
|
-
const keyFieldNames = this.keyFieldNamesByParentTypeName.get(typeName);
|
|
884
|
-
if (!keyFieldNames || !data.isEntity) {
|
|
885
|
-
nonEntityExtensionTypeNames.add(typeName);
|
|
886
|
-
continue;
|
|
887
|
-
}
|
|
888
|
-
this.validateEventDrivenKeyDefinition(typeName, invalidKeyFieldSetsByEntityTypeName);
|
|
889
|
-
this.validateEventDrivenObjectFields(data.fieldDataByFieldName, keyFieldNames, nonExternalKeyFieldNameByFieldPath, nonKeyFieldNameByFieldPath);
|
|
890
|
-
}
|
|
891
1152
|
for (const [typeName, data] of this.parentDefinitionDataByTypeName) {
|
|
892
1153
|
// validate edfs__PublishResult and edfs__NatsStreamConfiguration separately
|
|
893
1154
|
if (typeName === string_constants_1.EDFS_PUBLISH_RESULT || typeName === string_constants_1.EDFS_NATS_STREAM_CONFIGURATION) {
|
|
@@ -949,14 +1210,18 @@ class NormalizationFactory {
|
|
|
949
1210
|
}
|
|
950
1211
|
}
|
|
951
1212
|
validateUnionMembers(data) {
|
|
1213
|
+
if (data.memberByMemberTypeName.size < 1) {
|
|
1214
|
+
this.errors.push((0, errors_1.noDefinedUnionMembersError)(data.name));
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
952
1217
|
const invalidMembers = [];
|
|
953
1218
|
for (const memberName of data.memberByMemberTypeName.keys()) {
|
|
954
|
-
const memberData = this.parentDefinitionDataByTypeName.get(memberName)
|
|
1219
|
+
const memberData = this.parentDefinitionDataByTypeName.get(memberName);
|
|
955
1220
|
// Invalid references are propagated as an error elsewhere
|
|
956
1221
|
if (!memberData) {
|
|
957
1222
|
continue;
|
|
958
1223
|
}
|
|
959
|
-
if (memberData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION
|
|
1224
|
+
if (memberData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
960
1225
|
invalidMembers.push(`"${memberName}", which is type "${(0, utils_3.kindToTypeString)(memberData.kind)}"`);
|
|
961
1226
|
}
|
|
962
1227
|
}
|
|
@@ -975,7 +1240,7 @@ class NormalizationFactory {
|
|
|
975
1240
|
this.internalGraph.addEdge(this.internalGraph.addOrUpdateNode(interfaceName, { isAbstract: true }), this.internalGraph.addOrUpdateNode(concreteTypeName), concreteTypeName, true);
|
|
976
1241
|
}
|
|
977
1242
|
}
|
|
978
|
-
|
|
1243
|
+
addConcreteTypeNamesForUnion(node) {
|
|
979
1244
|
if (!node.types || node.types.length < 1) {
|
|
980
1245
|
return;
|
|
981
1246
|
}
|
|
@@ -995,13 +1260,9 @@ class NormalizationFactory {
|
|
|
995
1260
|
}
|
|
996
1261
|
validateAndAddKeysToConfiguration() {
|
|
997
1262
|
for (const [parentTypeName, keyFieldSetData] of this.keyFieldSetDataByTypeName) {
|
|
998
|
-
const parentData = this.parentDefinitionDataByTypeName.get(parentTypeName)
|
|
999
|
-
this.parentExtensionDataByTypeName.get(parentTypeName);
|
|
1263
|
+
const parentData = this.parentDefinitionDataByTypeName.get(parentTypeName);
|
|
1000
1264
|
if (!parentData ||
|
|
1001
|
-
(parentData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION &&
|
|
1002
|
-
parentData.kind != graphql_1.Kind.OBJECT_TYPE_EXTENSION &&
|
|
1003
|
-
parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION &&
|
|
1004
|
-
parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_EXTENSION)) {
|
|
1265
|
+
(parentData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION && parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION)) {
|
|
1005
1266
|
this.errors.push((0, errors_1.undefinedObjectLikeParentError)(parentTypeName));
|
|
1006
1267
|
continue;
|
|
1007
1268
|
}
|
|
@@ -1081,133 +1342,20 @@ class NormalizationFactory {
|
|
|
1081
1342
|
if (this.schemaDefinition.operationTypes.size > 0) {
|
|
1082
1343
|
definitions.push((0, utils_4.getSchemaNodeByData)(this.schemaDefinition, this.errors, this.directiveDefinitionByDirectiveName));
|
|
1083
1344
|
}
|
|
1084
|
-
const validParentExtensionOrphansByTypeName = new Map();
|
|
1085
|
-
const handledParentTypeNames = new Set();
|
|
1086
|
-
for (const [extensionTypeName, parentExtensionData] of this.parentExtensionDataByTypeName) {
|
|
1087
|
-
const isEntity = this.entityDataByTypeName.has(extensionTypeName);
|
|
1088
|
-
const newParentTypeName = parentExtensionData.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION
|
|
1089
|
-
? parentExtensionData.renamedTypeName || extensionTypeName
|
|
1090
|
-
: extensionTypeName;
|
|
1091
|
-
const configurationData = {
|
|
1092
|
-
fieldNames: new Set(),
|
|
1093
|
-
isRootNode: isEntity,
|
|
1094
|
-
typeName: newParentTypeName,
|
|
1095
|
-
};
|
|
1096
|
-
this.configurationDataByParentTypeName.set(newParentTypeName, configurationData);
|
|
1097
|
-
if (parentExtensionData.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
|
|
1098
|
-
if (this.operationTypeNodeByTypeName.has(extensionTypeName)) {
|
|
1099
|
-
configurationData.isRootNode = true;
|
|
1100
|
-
parentExtensionData.fieldDataByFieldName.delete(string_constants_1.SERVICE_FIELD);
|
|
1101
|
-
parentExtensionData.fieldDataByFieldName.delete(string_constants_1.ENTITIES_FIELD);
|
|
1102
|
-
}
|
|
1103
|
-
(0, utils_2.addFieldNamesToConfigurationData)(parentExtensionData.fieldDataByFieldName, configurationData);
|
|
1104
|
-
}
|
|
1105
|
-
const parentDefinitionData = this.parentDefinitionDataByTypeName.get(extensionTypeName);
|
|
1106
|
-
if (!parentDefinitionData) {
|
|
1107
|
-
if (parentExtensionData.kind !== graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
|
|
1108
|
-
this.errors.push((0, errors_1.noBaseTypeExtensionError)(extensionTypeName));
|
|
1109
|
-
}
|
|
1110
|
-
else {
|
|
1111
|
-
this.validateInterfaceImplementations(parentExtensionData);
|
|
1112
|
-
validParentExtensionOrphansByTypeName.set(extensionTypeName, parentExtensionData);
|
|
1113
|
-
definitions.push((0, utils_4.getParentWithFieldsNodeByData)(parentExtensionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName));
|
|
1114
|
-
}
|
|
1115
|
-
continue;
|
|
1116
|
-
}
|
|
1117
|
-
if (!(0, utils_1.areBaseAndExtensionKindsCompatible)(parentDefinitionData.kind, parentExtensionData.kind, extensionTypeName)) {
|
|
1118
|
-
this.errors.push((0, errors_1.incompatibleExtensionError)(extensionTypeName, parentDefinitionData.kind, parentExtensionData.kind));
|
|
1119
|
-
continue;
|
|
1120
|
-
}
|
|
1121
|
-
switch (parentDefinitionData.kind) {
|
|
1122
|
-
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
|
|
1123
|
-
const enumExtensionData = parentExtensionData;
|
|
1124
|
-
for (const [valueName, enumValueDefinitionNode] of enumExtensionData.enumValueDataByValueName) {
|
|
1125
|
-
if (!parentDefinitionData.enumValueDataByValueName.has(valueName)) {
|
|
1126
|
-
parentDefinitionData.enumValueDataByValueName.set(valueName, enumValueDefinitionNode);
|
|
1127
|
-
continue;
|
|
1128
|
-
}
|
|
1129
|
-
this.errors.push((0, errors_1.duplicateEnumValueDefinitionError)(valueName, extensionTypeName));
|
|
1130
|
-
}
|
|
1131
|
-
definitions.push((0, utils_4.getEnumNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName, enumExtensionData));
|
|
1132
|
-
break;
|
|
1133
|
-
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
1134
|
-
const inputObjectExtensionData = parentExtensionData;
|
|
1135
|
-
for (const [fieldName, inputValueDefinitionNode] of inputObjectExtensionData.inputValueDataByValueName) {
|
|
1136
|
-
if (!parentDefinitionData.inputValueDataByValueName.has(fieldName)) {
|
|
1137
|
-
parentDefinitionData.inputValueDataByValueName.set(fieldName, inputValueDefinitionNode);
|
|
1138
|
-
continue;
|
|
1139
|
-
}
|
|
1140
|
-
this.errors.push((0, errors_1.duplicateFieldDefinitionError)(fieldName, extensionTypeName));
|
|
1141
|
-
}
|
|
1142
|
-
definitions.push((0, utils_4.getInputObjectNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName, inputObjectExtensionData));
|
|
1143
|
-
break;
|
|
1144
|
-
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
1145
|
-
// intentional fallthrough
|
|
1146
|
-
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
1147
|
-
const extensionWithFieldsData = parentExtensionData;
|
|
1148
|
-
const operationTypeNode = this.operationTypeNodeByTypeName.get(extensionTypeName);
|
|
1149
|
-
const isObject = parentDefinitionData.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION;
|
|
1150
|
-
const externalInterfaceFieldNames = [];
|
|
1151
|
-
if (operationTypeNode) {
|
|
1152
|
-
configurationData.isRootNode = true;
|
|
1153
|
-
extensionWithFieldsData.fieldDataByFieldName.delete(string_constants_1.SERVICE_FIELD);
|
|
1154
|
-
extensionWithFieldsData.fieldDataByFieldName.delete(string_constants_1.ENTITIES_FIELD);
|
|
1155
|
-
}
|
|
1156
|
-
for (const [fieldName, fieldData] of extensionWithFieldsData.fieldDataByFieldName) {
|
|
1157
|
-
if (!isObject && fieldData.isExternalBySubgraphName.get(this.subgraphName)) {
|
|
1158
|
-
externalInterfaceFieldNames.push(fieldName);
|
|
1159
|
-
}
|
|
1160
|
-
if (fieldData.argumentDataByArgumentName.size > 0) {
|
|
1161
|
-
// Arguments can only be fully validated once all parents types are known
|
|
1162
|
-
this.validateArguments(fieldData, `${extensionTypeName}.${fieldName}`);
|
|
1163
|
-
}
|
|
1164
|
-
if (parentDefinitionData.fieldDataByFieldName.has(fieldName)) {
|
|
1165
|
-
this.errors.push((0, errors_1.duplicateFieldDefinitionError)(fieldName, extensionTypeName));
|
|
1166
|
-
continue;
|
|
1167
|
-
}
|
|
1168
|
-
parentDefinitionData.fieldDataByFieldName.set(fieldName, fieldData);
|
|
1169
|
-
if (!fieldData.argumentDataByArgumentName.has(string_constants_1.EXTERNAL)) {
|
|
1170
|
-
configurationData.fieldNames.add(fieldName);
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
this.mergeUniqueInterfaces(extensionWithFieldsData.implementedInterfaceTypeNames, parentDefinitionData.implementedInterfaceTypeNames, extensionTypeName);
|
|
1174
|
-
this.validateInterfaceImplementations(parentDefinitionData);
|
|
1175
|
-
definitions.push((0, utils_4.getParentWithFieldsNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName, extensionWithFieldsData));
|
|
1176
|
-
if (externalInterfaceFieldNames.length > 0) {
|
|
1177
|
-
this.isSubgraphVersionTwo
|
|
1178
|
-
? this.errors.push((0, errors_1.externalInterfaceFieldsError)(extensionTypeName, externalInterfaceFieldNames))
|
|
1179
|
-
: this.warnings.push((0, warnings_1.externalInterfaceFieldsWarning)(this.subgraphName, extensionTypeName, externalInterfaceFieldNames));
|
|
1180
|
-
}
|
|
1181
|
-
// Interfaces and objects must define at least one field
|
|
1182
|
-
if (parentDefinitionData.fieldDataByFieldName.size < 1 &&
|
|
1183
|
-
!(0, utils_2.isNodeQuery)(extensionTypeName, operationTypeNode)) {
|
|
1184
|
-
this.errors.push((0, errors_1.noFieldDefinitionsError)((0, utils_3.kindToTypeString)(parentDefinitionData.kind), extensionTypeName));
|
|
1185
|
-
}
|
|
1186
|
-
// Add the base type field names to the configuration data
|
|
1187
|
-
(0, utils_2.addFieldNamesToConfigurationData)(parentDefinitionData.fieldDataByFieldName, configurationData);
|
|
1188
|
-
break;
|
|
1189
|
-
case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
|
|
1190
|
-
definitions.push((0, utils_4.getScalarNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, parentExtensionData));
|
|
1191
|
-
break;
|
|
1192
|
-
case graphql_1.Kind.UNION_TYPE_DEFINITION:
|
|
1193
|
-
definitions.push((0, utils_4.getUnionNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, parentExtensionData));
|
|
1194
|
-
this.validateUnionMembers(parentDefinitionData);
|
|
1195
|
-
break;
|
|
1196
|
-
default:
|
|
1197
|
-
throw (0, errors_1.unexpectedKindFatalError)(extensionTypeName);
|
|
1198
|
-
}
|
|
1199
|
-
// At this point, the base type has been dealt with, so it doesn't need to be dealt with again
|
|
1200
|
-
handledParentTypeNames.add(extensionTypeName);
|
|
1201
|
-
}
|
|
1202
1345
|
for (const [parentTypeName, parentDefinitionData] of this.parentDefinitionDataByTypeName) {
|
|
1203
|
-
if (handledParentTypeNames.has(parentTypeName)) {
|
|
1204
|
-
continue;
|
|
1205
|
-
}
|
|
1206
1346
|
switch (parentDefinitionData.kind) {
|
|
1207
1347
|
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
|
|
1348
|
+
if (parentDefinitionData.enumValueDataByValueName.size < 1) {
|
|
1349
|
+
this.errors.push((0, errors_1.noDefinedEnumValuesError)(parentTypeName));
|
|
1350
|
+
break;
|
|
1351
|
+
}
|
|
1208
1352
|
definitions.push((0, utils_4.getEnumNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName));
|
|
1209
1353
|
break;
|
|
1210
1354
|
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
1355
|
+
if (parentDefinitionData.inputValueDataByValueName.size < 1) {
|
|
1356
|
+
this.errors.push((0, errors_1.noInputValueDefinitionsError)(parentTypeName));
|
|
1357
|
+
break;
|
|
1358
|
+
}
|
|
1211
1359
|
definitions.push((0, utils_4.getInputObjectNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName));
|
|
1212
1360
|
break;
|
|
1213
1361
|
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
@@ -1258,13 +1406,17 @@ class NormalizationFactory {
|
|
|
1258
1406
|
this.configurationDataByParentTypeName.set(newParentTypeName, configurationData);
|
|
1259
1407
|
(0, utils_2.addFieldNamesToConfigurationData)(parentDefinitionData.fieldDataByFieldName, configurationData);
|
|
1260
1408
|
this.validateInterfaceImplementations(parentDefinitionData);
|
|
1261
|
-
definitions.push((0, utils_4.
|
|
1409
|
+
definitions.push((0, utils_4.getCompositeOutputNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName, this.authorizationDataByParentTypeName));
|
|
1262
1410
|
// interfaces and objects must define at least one field
|
|
1263
1411
|
if (parentDefinitionData.fieldDataByFieldName.size < 1 && !(0, utils_2.isNodeQuery)(parentTypeName, operationTypeNode)) {
|
|
1264
1412
|
this.errors.push((0, errors_1.noFieldDefinitionsError)((0, utils_3.kindToTypeString)(parentDefinitionData.kind), parentTypeName));
|
|
1265
1413
|
}
|
|
1266
1414
|
break;
|
|
1267
1415
|
case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
|
|
1416
|
+
if (parentDefinitionData.extensionType === type_definition_data_1.ExtensionType.REAL) {
|
|
1417
|
+
this.errors.push((0, errors_1.noBaseScalarDefinitionError)(parentTypeName));
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1268
1420
|
definitions.push((0, utils_4.getScalarNodeByData)(parentDefinitionData, this.errors, this.directiveDefinitionByDirectiveName));
|
|
1269
1421
|
break;
|
|
1270
1422
|
case graphql_1.Kind.UNION_TYPE_DEFINITION:
|
|
@@ -1282,25 +1434,22 @@ class NormalizationFactory {
|
|
|
1282
1434
|
// If an operation type name was not declared, use the default
|
|
1283
1435
|
const operationTypeName = operationTypeNode ? (0, ast_1.getTypeNodeNamedTypeName)(operationTypeNode.type) : defaultTypeName;
|
|
1284
1436
|
// If a custom type is used, the default type should not be defined
|
|
1285
|
-
if (operationTypeName !== defaultTypeName &&
|
|
1286
|
-
(this.parentDefinitionDataByTypeName.has(defaultTypeName) ||
|
|
1287
|
-
this.parentExtensionDataByTypeName.has(defaultTypeName))) {
|
|
1437
|
+
if (operationTypeName !== defaultTypeName && this.parentDefinitionDataByTypeName.has(defaultTypeName)) {
|
|
1288
1438
|
this.errors.push((0, errors_1.invalidRootTypeDefinitionError)(operationType, operationTypeName, defaultTypeName));
|
|
1289
1439
|
continue;
|
|
1290
1440
|
}
|
|
1291
1441
|
const objectData = this.parentDefinitionDataByTypeName.get(operationTypeName);
|
|
1292
|
-
const extensionData = this.parentExtensionDataByTypeName.get(operationTypeName);
|
|
1293
1442
|
// operationTypeNode is truthy if an operation type was explicitly declared
|
|
1294
1443
|
if (operationTypeNode) {
|
|
1295
1444
|
// If the type is not defined in the schema, it's always an error
|
|
1296
|
-
if (!objectData
|
|
1445
|
+
if (!objectData) {
|
|
1297
1446
|
this.errors.push((0, errors_1.undefinedTypeError)(operationTypeName));
|
|
1298
1447
|
continue;
|
|
1299
1448
|
}
|
|
1300
1449
|
// Add the explicitly defined type to the map for the federation-factory
|
|
1301
1450
|
this.operationTypeNodeByTypeName.set(operationTypeName, operationType);
|
|
1302
1451
|
}
|
|
1303
|
-
if (!objectData
|
|
1452
|
+
if (!objectData) {
|
|
1304
1453
|
continue;
|
|
1305
1454
|
}
|
|
1306
1455
|
const rootNode = this.configurationDataByParentTypeName.get(defaultTypeName);
|
|
@@ -1308,46 +1457,28 @@ class NormalizationFactory {
|
|
|
1308
1457
|
rootNode.isRootNode = true;
|
|
1309
1458
|
rootNode.typeName = defaultTypeName;
|
|
1310
1459
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
}
|
|
1320
|
-
// Root types fields whose response type is an extension orphan could be valid through a federated graph
|
|
1321
|
-
// However, the field would have to be shareable to ever be valid TODO
|
|
1322
|
-
for (const fieldData of parentData.fieldDataByFieldName.values()) {
|
|
1323
|
-
const fieldTypeName = (0, ast_1.getTypeNodeNamedTypeName)(fieldData.node.type);
|
|
1324
|
-
if (!constants_1.BASE_SCALARS.has(fieldTypeName) &&
|
|
1325
|
-
!this.parentDefinitionDataByTypeName.has(fieldTypeName) &&
|
|
1326
|
-
!validParentExtensionOrphansByTypeName.has(fieldTypeName)) {
|
|
1327
|
-
this.errors.push((0, errors_1.undefinedTypeError)(fieldTypeName));
|
|
1328
|
-
}
|
|
1460
|
+
if (objectData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
1461
|
+
this.errors.push((0, errors_1.operationDefinitionError)(operationTypeName, operationType, objectData.kind));
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
for (const fieldData of objectData.fieldDataByFieldName.values()) {
|
|
1465
|
+
const fieldTypeName = (0, ast_1.getTypeNodeNamedTypeName)(fieldData.node.type);
|
|
1466
|
+
if (!constants_1.BASE_SCALARS.has(fieldTypeName) && !this.parentDefinitionDataByTypeName.has(fieldTypeName)) {
|
|
1467
|
+
this.errors.push((0, errors_1.undefinedTypeError)(fieldTypeName));
|
|
1329
1468
|
}
|
|
1330
1469
|
}
|
|
1331
1470
|
}
|
|
1332
1471
|
for (const referencedTypeName of this.referencedTypeNames) {
|
|
1333
|
-
if (this.parentDefinitionDataByTypeName.has(referencedTypeName)
|
|
1334
|
-
this.entityDataByTypeName.has(referencedTypeName)) {
|
|
1335
|
-
continue;
|
|
1336
|
-
}
|
|
1337
|
-
const extension = this.parentExtensionDataByTypeName.get(referencedTypeName);
|
|
1338
|
-
if (!extension || extension.kind !== graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
|
|
1472
|
+
if (!this.parentDefinitionDataByTypeName.has(referencedTypeName) &&
|
|
1473
|
+
!this.entityDataByTypeName.has(referencedTypeName)) {
|
|
1339
1474
|
this.errors.push((0, errors_1.undefinedTypeError)(referencedTypeName));
|
|
1340
1475
|
}
|
|
1341
1476
|
}
|
|
1342
1477
|
this.validateAndAddKeysToConfiguration();
|
|
1343
1478
|
for (const [parentTypeName, fieldSetData] of this.fieldSetDataByTypeName) {
|
|
1344
|
-
const parentData = this.parentDefinitionDataByTypeName.get(parentTypeName)
|
|
1345
|
-
this.parentExtensionDataByTypeName.get(parentTypeName);
|
|
1479
|
+
const parentData = this.parentDefinitionDataByTypeName.get(parentTypeName);
|
|
1346
1480
|
if (!parentData ||
|
|
1347
|
-
(parentData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION &&
|
|
1348
|
-
parentData.kind != graphql_1.Kind.OBJECT_TYPE_EXTENSION &&
|
|
1349
|
-
parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION &&
|
|
1350
|
-
parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_EXTENSION)) {
|
|
1481
|
+
(parentData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION && parentData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION)) {
|
|
1351
1482
|
this.errors.push((0, errors_1.undefinedObjectLikeParentError)(parentTypeName));
|
|
1352
1483
|
continue;
|
|
1353
1484
|
}
|
|
@@ -1391,7 +1522,6 @@ class NormalizationFactory {
|
|
|
1391
1522
|
originalTypeNameByRenamedTypeName: this.originalTypeNameByRenamedTypeName,
|
|
1392
1523
|
overridesByTargetSubgraphName: this.overridesByTargetSubgraphName,
|
|
1393
1524
|
parentDefinitionDataByTypeName: this.parentDefinitionDataByTypeName,
|
|
1394
|
-
parentExtensionDataByTypeName: validParentExtensionOrphansByTypeName,
|
|
1395
1525
|
persistedDirectiveDefinitionDataByDirectiveName,
|
|
1396
1526
|
subgraphAST: newAST,
|
|
1397
1527
|
subgraphString: (0, graphql_1.print)(newAST),
|
|
@@ -1469,7 +1599,6 @@ function batchNormalize(subgraphs) {
|
|
|
1469
1599
|
operationTypes: normalizationResult.operationTypes,
|
|
1470
1600
|
overriddenFieldNamesByParentTypeName: new Map(),
|
|
1471
1601
|
parentDefinitionDataByTypeName: normalizationResult.parentDefinitionDataByTypeName,
|
|
1472
|
-
parentExtensionDataByTypeName: normalizationResult.parentExtensionDataByTypeName,
|
|
1473
1602
|
persistedDirectiveDefinitionDataByDirectiveName: normalizationResult.persistedDirectiveDefinitionDataByDirectiveName,
|
|
1474
1603
|
schema: normalizationResult.schema,
|
|
1475
1604
|
url: subgraph.url,
|