@theguild/federation-composition 0.3.0 → 0.3.1-alpha-20231213180609-e22c4e4
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/supergraph/validation/rules/invalid-field-sharing-rule.js +7 -1
- package/cjs/supergraph/validation/rules/override-source-has-override.js +2 -2
- package/cjs/supergraph/validation/validation-context.js +8 -0
- package/esm/supergraph/validation/rules/invalid-field-sharing-rule.js +7 -1
- package/esm/supergraph/validation/rules/override-source-has-override.js +2 -2
- package/esm/supergraph/validation/validation-context.js +8 -0
- package/package.json +1 -1
- package/typings/supergraph/validation/validation-context.d.cts +1 -0
- package/typings/supergraph/validation/validation-context.d.ts +1 -0
|
@@ -18,9 +18,15 @@ function InvalidFieldSharingRule(context) {
|
|
|
18
18
|
const fieldIsExternal = field.external;
|
|
19
19
|
const fieldHasOverride = field.override;
|
|
20
20
|
const fieldIsUsedAsKey = field.usedAsKey;
|
|
21
|
-
if (fieldIsExternal
|
|
21
|
+
if (fieldIsExternal) {
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
+
if (fieldHasOverride) {
|
|
25
|
+
const overrideGraphId = context.graphNameToId(fieldHasOverride);
|
|
26
|
+
if (overrideGraphId && fieldState.byGraph.has(overrideGraphId)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
if (objectTypeIsShareable || fieldIsShareable || fieldIsUsedAsKey) {
|
|
25
31
|
resolvableIn.push(graphId);
|
|
26
32
|
continue;
|
|
@@ -14,8 +14,8 @@ function OverrideSourceHasOverrideRule(context) {
|
|
|
14
14
|
}
|
|
15
15
|
for (let i = 0; i < graphsWithOverride.length; i++) {
|
|
16
16
|
const [graph, fieldStateInGraph] = graphsWithOverride[i];
|
|
17
|
-
const overrideValue = fieldStateInGraph.override
|
|
18
|
-
const graphFromOverride = fieldState.byGraph.get(overrideValue);
|
|
17
|
+
const overrideValue = context.graphNameToId(fieldStateInGraph.override);
|
|
18
|
+
const graphFromOverride = overrideValue ? fieldState.byGraph.get(overrideValue) : null;
|
|
19
19
|
const anotherGraphId = graphFromOverride && graphFromOverride.override !== null
|
|
20
20
|
? overrideValue
|
|
21
21
|
: graphsWithOverride[i + 1]
|
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createSupergraphValidationContext = void 0;
|
|
4
4
|
function createSupergraphValidationContext(subgraphStates) {
|
|
5
5
|
let reportedErrors = [];
|
|
6
|
+
const subgraphNameToIdMap = {};
|
|
7
|
+
for (const [id, state] of subgraphStates) {
|
|
8
|
+
subgraphNameToIdMap[state.graph.name] = id;
|
|
9
|
+
}
|
|
6
10
|
return {
|
|
7
11
|
subgraphStates,
|
|
8
12
|
graphIdToName(id) {
|
|
@@ -12,6 +16,10 @@ function createSupergraphValidationContext(subgraphStates) {
|
|
|
12
16
|
}
|
|
13
17
|
return found.graph.name;
|
|
14
18
|
},
|
|
19
|
+
graphNameToId(name) {
|
|
20
|
+
const found = subgraphNameToIdMap[name];
|
|
21
|
+
return found ?? null;
|
|
22
|
+
},
|
|
15
23
|
reportError(error) {
|
|
16
24
|
reportedErrors.push(error);
|
|
17
25
|
},
|
|
@@ -15,9 +15,15 @@ export function InvalidFieldSharingRule(context) {
|
|
|
15
15
|
const fieldIsExternal = field.external;
|
|
16
16
|
const fieldHasOverride = field.override;
|
|
17
17
|
const fieldIsUsedAsKey = field.usedAsKey;
|
|
18
|
-
if (fieldIsExternal
|
|
18
|
+
if (fieldIsExternal) {
|
|
19
19
|
continue;
|
|
20
20
|
}
|
|
21
|
+
if (fieldHasOverride) {
|
|
22
|
+
const overrideGraphId = context.graphNameToId(fieldHasOverride);
|
|
23
|
+
if (overrideGraphId && fieldState.byGraph.has(overrideGraphId)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
21
27
|
if (objectTypeIsShareable || fieldIsShareable || fieldIsUsedAsKey) {
|
|
22
28
|
resolvableIn.push(graphId);
|
|
23
29
|
continue;
|
|
@@ -11,8 +11,8 @@ export function OverrideSourceHasOverrideRule(context) {
|
|
|
11
11
|
}
|
|
12
12
|
for (let i = 0; i < graphsWithOverride.length; i++) {
|
|
13
13
|
const [graph, fieldStateInGraph] = graphsWithOverride[i];
|
|
14
|
-
const overrideValue = fieldStateInGraph.override
|
|
15
|
-
const graphFromOverride = fieldState.byGraph.get(overrideValue);
|
|
14
|
+
const overrideValue = context.graphNameToId(fieldStateInGraph.override);
|
|
15
|
+
const graphFromOverride = overrideValue ? fieldState.byGraph.get(overrideValue) : null;
|
|
16
16
|
const anotherGraphId = graphFromOverride && graphFromOverride.override !== null
|
|
17
17
|
? overrideValue
|
|
18
18
|
: graphsWithOverride[i + 1]
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export function createSupergraphValidationContext(subgraphStates) {
|
|
2
2
|
let reportedErrors = [];
|
|
3
|
+
const subgraphNameToIdMap = {};
|
|
4
|
+
for (const [id, state] of subgraphStates) {
|
|
5
|
+
subgraphNameToIdMap[state.graph.name] = id;
|
|
6
|
+
}
|
|
3
7
|
return {
|
|
4
8
|
subgraphStates,
|
|
5
9
|
graphIdToName(id) {
|
|
@@ -9,6 +13,10 @@ export function createSupergraphValidationContext(subgraphStates) {
|
|
|
9
13
|
}
|
|
10
14
|
return found.graph.name;
|
|
11
15
|
},
|
|
16
|
+
graphNameToId(name) {
|
|
17
|
+
const found = subgraphNameToIdMap[name];
|
|
18
|
+
return found ?? null;
|
|
19
|
+
},
|
|
12
20
|
reportError(error) {
|
|
13
21
|
reportedErrors.push(error);
|
|
14
22
|
},
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ export type SupergraphValidationContext = ReturnType<typeof createSupergraphVali
|
|
|
4
4
|
export declare function createSupergraphValidationContext(subgraphStates: Map<string, SubgraphState>): {
|
|
5
5
|
subgraphStates: Map<string, SubgraphState>;
|
|
6
6
|
graphIdToName(id: string): string;
|
|
7
|
+
graphNameToId(name: string): string | null;
|
|
7
8
|
reportError(error: GraphQLError): void;
|
|
8
9
|
collectReportedErrors(): GraphQLError[];
|
|
9
10
|
};
|
|
@@ -4,6 +4,7 @@ export type SupergraphValidationContext = ReturnType<typeof createSupergraphVali
|
|
|
4
4
|
export declare function createSupergraphValidationContext(subgraphStates: Map<string, SubgraphState>): {
|
|
5
5
|
subgraphStates: Map<string, SubgraphState>;
|
|
6
6
|
graphIdToName(id: string): string;
|
|
7
|
+
graphNameToId(name: string): string | null;
|
|
7
8
|
reportError(error: GraphQLError): void;
|
|
8
9
|
collectReportedErrors(): GraphQLError[];
|
|
9
10
|
};
|