Skip to content

Commit c7c334d

Browse files
authored
Fixed FED 644 (#7929)
1 parent 8d60853 commit c7c334d

File tree

4 files changed

+178
-1
lines changed

4 files changed

+178
-1
lines changed

apollo-federation/src/query_graph/graph_path.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,8 @@ where
23422342

23432343
if let Some(conditions) = &edge.conditions {
23442344
write!(f, " --[{conditions} ⊢ {label}]--> {node}")
2345+
} else if let Some(conditions) = &edge.override_condition {
2346+
write!(f, " --[{conditions} ⊢ {label}]--> {node}")
23452347
} else if !matches!(
23462348
edge.transition,
23472349
QueryGraphEdgeTransition::SubgraphEnteringTransition

apollo-federation/src/supergraph/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ fn add_subgraph_field(
15671567
));
15681568
}
15691569
let user_overridden = field_directive_application.user_overridden.unwrap_or(false);
1570-
if user_overridden {
1570+
if user_overridden && field_directive_application.override_label.is_none() {
15711571
subgraph_field.directives.push(Node::new(
15721572
federation_spec_definition
15731573
.external_directive(&subgraph.schema, Some("[overridden]".to_string()))?,

apollo-federation/tests/query_plan/build_query_plan_tests/overrides.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,88 @@ fn it_does_not_override_unset_labels_on_nested_entity_fields() {
376376
"###
377377
);
378378
}
379+
380+
#[test]
381+
fn override_a_field_from_an_interface() {
382+
let planner = planner!(
383+
subgraphA: r#"
384+
interface IImage {
385+
id: ID!
386+
absoluteUri: String!
387+
}
388+
type Image implements IImage @key(fields: "id") {
389+
id: ID!
390+
absoluteUri: String!
391+
}
392+
extend type AssetMetadata @key(fields: "id") {
393+
id: ID!
394+
image: Image
395+
}
396+
"#,
397+
subgraphB: r#"
398+
type Image @key(fields: "id") {
399+
id: ID!
400+
absoluteUri: String! @override(from: "subgraphA", label: "percent(1)")
401+
}
402+
type AssetMetadata @key(fields: "id") {
403+
id: ID!
404+
image: Image @override(from: "subgraphA", label: "percent(1)")
405+
}
406+
"#,
407+
subgraphC: r#"
408+
type Query {
409+
assetMetadata(id: ID!): AssetMetadata
410+
}
411+
type AssetMetadata @key(fields: "id") {
412+
id: ID!
413+
name: String!
414+
}
415+
"#,
416+
);
417+
418+
assert_plan!(
419+
&planner,
420+
r#"
421+
query TestQuery($id: ID!) {
422+
assetMetadata(id: $id) {
423+
__typename
424+
image {
425+
absoluteUri
426+
}
427+
}
428+
}
429+
"#,
430+
@r###"
431+
QueryPlan {
432+
Sequence {
433+
Fetch(service: "subgraphC") {
434+
{
435+
assetMetadata(id: $id) {
436+
__typename
437+
id
438+
}
439+
}
440+
},
441+
Flatten(path: "assetMetadata") {
442+
Fetch(service: "subgraphA") {
443+
{
444+
... on AssetMetadata {
445+
__typename
446+
id
447+
}
448+
} =>
449+
{
450+
... on AssetMetadata {
451+
__typename
452+
image {
453+
absoluteUri
454+
}
455+
}
456+
}
457+
},
458+
},
459+
},
460+
}
461+
"###
462+
);
463+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Composed from subgraphs with hash: 11b8b04d27652c8709c30bd23bf203a9f1cf2879
2+
schema
3+
@link(url: "https://specs.apollo.dev/link/v1.0")
4+
@link(url: "https://specs.apollo.dev/join/v0.5", for: EXECUTION)
5+
{
6+
query: Query
7+
}
8+
9+
directive @join__directive(graphs: [join__Graph!], name: String!, args: join__DirectiveArguments) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION
10+
11+
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
12+
13+
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean, overrideLabel: String, contextArguments: [join__ContextArgument!]) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
14+
15+
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
16+
17+
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
18+
19+
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
20+
21+
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
22+
23+
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
24+
25+
type AssetMetadata
26+
@join__type(graph: SUBGRAPHA, key: "id", extension: true)
27+
@join__type(graph: SUBGRAPHB, key: "id")
28+
@join__type(graph: SUBGRAPHC, key: "id")
29+
{
30+
id: ID!
31+
image: Image @join__field(graph: SUBGRAPHA, overrideLabel: "percent(1)") @join__field(graph: SUBGRAPHB, override: "subgraphA", overrideLabel: "percent(1)")
32+
name: String! @join__field(graph: SUBGRAPHC)
33+
}
34+
35+
interface IImage
36+
@join__type(graph: SUBGRAPHA)
37+
{
38+
id: ID!
39+
absoluteUri: String!
40+
}
41+
42+
type Image implements IImage
43+
@join__implements(graph: SUBGRAPHA, interface: "IImage")
44+
@join__type(graph: SUBGRAPHA, key: "id")
45+
@join__type(graph: SUBGRAPHB, key: "id")
46+
{
47+
id: ID!
48+
absoluteUri: String! @join__field(graph: SUBGRAPHA, usedOverridden: true, overrideLabel: "percent(1)") @join__field(graph: SUBGRAPHB, override: "subgraphA", overrideLabel: "percent(1)")
49+
}
50+
51+
input join__ContextArgument {
52+
name: String!
53+
type: String!
54+
context: String!
55+
selection: join__FieldValue!
56+
}
57+
58+
scalar join__DirectiveArguments
59+
60+
scalar join__FieldSet
61+
62+
scalar join__FieldValue
63+
64+
enum join__Graph {
65+
SUBGRAPHA @join__graph(name: "subgraphA", url: "none")
66+
SUBGRAPHB @join__graph(name: "subgraphB", url: "none")
67+
SUBGRAPHC @join__graph(name: "subgraphC", url: "none")
68+
}
69+
70+
scalar link__Import
71+
72+
enum link__Purpose {
73+
"""
74+
`SECURITY` features provide metadata necessary to securely resolve fields.
75+
"""
76+
SECURITY
77+
78+
"""
79+
`EXECUTION` features provide metadata necessary for operation execution.
80+
"""
81+
EXECUTION
82+
}
83+
84+
type Query
85+
@join__type(graph: SUBGRAPHA)
86+
@join__type(graph: SUBGRAPHB)
87+
@join__type(graph: SUBGRAPHC)
88+
{
89+
assetMetadata(id: ID!): AssetMetadata @join__field(graph: SUBGRAPHC)
90+
}

0 commit comments

Comments
 (0)