@theguild/federation-composition 0.11.3 → 0.11.4-alpha-20240625144413-7c50afe
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/cjs/subgraph/validation/validate-state.js +1 -1
- package/cjs/supergraph/validation/rules/interface-subtype-rule.js +32 -0
- package/cjs/supergraph/validation/validate-supergraph.js +2 -0
- package/esm/graphql/contains-supergraph-spec.js +1 -1
- package/esm/subgraph/validation/validate-state.js +1 -1
- package/esm/supergraph/validation/rules/interface-subtype-rule.js +28 -0
- package/esm/supergraph/validation/validate-supergraph.js +2 -0
- package/package.json +1 -1
- package/typings/supergraph/validation/rules/interface-subtype-rule.d.cts +5 -0
- package/typings/supergraph/validation/rules/interface-subtype-rule.d.ts +5 -0
|
@@ -344,7 +344,7 @@ function validateTypeImplementsInterface(state, implementationsMap, reportError,
|
|
|
344
344
|
}
|
|
345
345
|
if (!isTypeSubTypeOf(state, implementationsMap, typeField.type, ifaceField.type)) {
|
|
346
346
|
reportError(`Interface field ${interfaceType.name}.${fieldName} expects type ` +
|
|
347
|
-
`${ifaceField.type} but ${type.name}.${fieldName}
|
|
347
|
+
`${ifaceField.type} but ${type.name}.${fieldName} of type ${typeField.type} is not a proper subtype.`);
|
|
348
348
|
}
|
|
349
349
|
for (const ifaceArg of ifaceField.args.values()) {
|
|
350
350
|
const argName = ifaceArg.name;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterfaceSubtypeRule = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
function InterfaceSubtypeRule(context, supergraph) {
|
|
6
|
+
return {
|
|
7
|
+
ObjectTypeField(objectTypeState, fieldState) {
|
|
8
|
+
if (objectTypeState.interfaces.size === 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const interfaceNames = Array.from(objectTypeState.interfaces.values());
|
|
12
|
+
for (const interfaceName of interfaceNames) {
|
|
13
|
+
const interfaceState = supergraph.interfaceTypes.get(interfaceName);
|
|
14
|
+
if (!interfaceState) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const interfaceField = interfaceState.fields.get(fieldState.name);
|
|
18
|
+
if (!interfaceField) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (fieldState.type !== interfaceField.type) {
|
|
22
|
+
context.reportError(new graphql_1.GraphQLError(`Interface field ${interfaceName}.${interfaceField.name} expects type ${interfaceField.type} but ${objectTypeState.name}.${fieldState.name} of type ${fieldState.type} is not a proper subtype.`, {
|
|
23
|
+
extensions: {
|
|
24
|
+
code: 'INVALID_GRAPHQL',
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.InterfaceSubtypeRule = InterfaceSubtypeRule;
|
|
@@ -16,6 +16,7 @@ const input_field_default_mismatch_rule_js_1 = require("./rules/input-field-defa
|
|
|
16
16
|
const input_object_values_rule_js_1 = require("./rules/input-object-values-rule.js");
|
|
17
17
|
const interface_key_missing_implementation_type_js_1 = require("./rules/interface-key-missing-implementation-type.js");
|
|
18
18
|
const interface_object_usage_error_js_1 = require("./rules/interface-object-usage-error.js");
|
|
19
|
+
const interface_subtype_rule_js_1 = require("./rules/interface-subtype-rule.js");
|
|
19
20
|
const invalid_field_sharing_rule_js_1 = require("./rules/invalid-field-sharing-rule.js");
|
|
20
21
|
const only_inaccessible_children_rule_js_1 = require("./rules/only-inaccessible-children-rule.js");
|
|
21
22
|
const override_source_has_override_js_1 = require("./rules/override-source-has-override.js");
|
|
@@ -68,6 +69,7 @@ function validateSupergraph(subgraphStates, state, __internal) {
|
|
|
68
69
|
satisfiablity_rule_js_1.SatisfiabilityRule,
|
|
69
70
|
subgraph_name_rule_js_1.SubgraphNameRule,
|
|
70
71
|
required_argument_or_field_is_not_inaccessible_rule_js_1.RequiredArgumentOrFieldIsNotInaccessibleRule,
|
|
72
|
+
interface_subtype_rule_js_1.InterfaceSubtypeRule,
|
|
71
73
|
];
|
|
72
74
|
const supergraph = state.getSupergraphState();
|
|
73
75
|
(0, visitor_js_1.visitSupergraphState)(supergraph, postSupergraphRules.map(rule => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { federationDirectives, federationEnums, federationScalars } from
|
|
1
|
+
import { federationDirectives, federationEnums, federationScalars, } from './transform-supergraph-to-public-schema.js';
|
|
2
2
|
const supergraphSpecDetectionRegex = new RegExp(Array.from(federationScalars)
|
|
3
3
|
.concat(Array.from(federationEnums))
|
|
4
4
|
.map(name => [`\\[${name}`, `\\s${name}`])
|
|
@@ -340,7 +340,7 @@ function validateTypeImplementsInterface(state, implementationsMap, reportError,
|
|
|
340
340
|
}
|
|
341
341
|
if (!isTypeSubTypeOf(state, implementationsMap, typeField.type, ifaceField.type)) {
|
|
342
342
|
reportError(`Interface field ${interfaceType.name}.${fieldName} expects type ` +
|
|
343
|
-
`${ifaceField.type} but ${type.name}.${fieldName}
|
|
343
|
+
`${ifaceField.type} but ${type.name}.${fieldName} of type ${typeField.type} is not a proper subtype.`);
|
|
344
344
|
}
|
|
345
345
|
for (const ifaceArg of ifaceField.args.values()) {
|
|
346
346
|
const argName = ifaceArg.name;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
export function InterfaceSubtypeRule(context, supergraph) {
|
|
3
|
+
return {
|
|
4
|
+
ObjectTypeField(objectTypeState, fieldState) {
|
|
5
|
+
if (objectTypeState.interfaces.size === 0) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const interfaceNames = Array.from(objectTypeState.interfaces.values());
|
|
9
|
+
for (const interfaceName of interfaceNames) {
|
|
10
|
+
const interfaceState = supergraph.interfaceTypes.get(interfaceName);
|
|
11
|
+
if (!interfaceState) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const interfaceField = interfaceState.fields.get(fieldState.name);
|
|
15
|
+
if (!interfaceField) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (fieldState.type !== interfaceField.type) {
|
|
19
|
+
context.reportError(new GraphQLError(`Interface field ${interfaceName}.${interfaceField.name} expects type ${interfaceField.type} but ${objectTypeState.name}.${fieldState.name} of type ${fieldState.type} is not a proper subtype.`, {
|
|
20
|
+
extensions: {
|
|
21
|
+
code: 'INVALID_GRAPHQL',
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -13,6 +13,7 @@ import { InputFieldDefaultMismatchRule } from './rules/input-field-default-misma
|
|
|
13
13
|
import { InputObjectValuesRule } from './rules/input-object-values-rule.js';
|
|
14
14
|
import { InterfaceKeyMissingImplementationTypeRule } from './rules/interface-key-missing-implementation-type.js';
|
|
15
15
|
import { InterfaceObjectUsageErrorRule } from './rules/interface-object-usage-error.js';
|
|
16
|
+
import { InterfaceSubtypeRule } from './rules/interface-subtype-rule.js';
|
|
16
17
|
import { InvalidFieldSharingRule } from './rules/invalid-field-sharing-rule.js';
|
|
17
18
|
import { OnlyInaccessibleChildrenRule } from './rules/only-inaccessible-children-rule.js';
|
|
18
19
|
import { OverrideSourceHasOverrideRule } from './rules/override-source-has-override.js';
|
|
@@ -65,6 +66,7 @@ export function validateSupergraph(subgraphStates, state, __internal) {
|
|
|
65
66
|
SatisfiabilityRule,
|
|
66
67
|
SubgraphNameRule,
|
|
67
68
|
RequiredArgumentOrFieldIsNotInaccessibleRule,
|
|
69
|
+
InterfaceSubtypeRule,
|
|
68
70
|
];
|
|
69
71
|
const supergraph = state.getSupergraphState();
|
|
70
72
|
visitSupergraphState(supergraph, postSupergraphRules.map(rule => {
|
package/package.json
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SupergraphVisitorMap } from '../../composition/visitor.cjs';
|
|
2
|
+
import { SupergraphState } from '../../state.cjs';
|
|
3
|
+
import { SupergraphValidationContext } from '../validation-context.cjs';
|
|
4
|
+
export declare function InterfaceSubtypeRule(context: SupergraphValidationContext, supergraph: SupergraphState): SupergraphVisitorMap;
|
|
5
|
+
//# sourceMappingURL=interface-subtype-rule.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SupergraphVisitorMap } from '../../composition/visitor.js';
|
|
2
|
+
import { SupergraphState } from '../../state.js';
|
|
3
|
+
import { SupergraphValidationContext } from '../validation-context.js';
|
|
4
|
+
export declare function InterfaceSubtypeRule(context: SupergraphValidationContext, supergraph: SupergraphState): SupergraphVisitorMap;
|
|
5
|
+
//# sourceMappingURL=interface-subtype-rule.d.ts.map
|