Skip to content

Commit 1714bb2

Browse files
authored
fix(composition): Check value of resolvable arg when looking for resolvable keys (#8694)
1 parent 82dc6c3 commit 1714bb2

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

apollo-federation/src/merger/merge_interface.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ impl Merger {
3737
let interface_pos: TypeDefinitionPosition = dest.clone().into();
3838
let keys = interface_pos.get_applied_directives(subgraph.schema(), &key_directive_name);
3939
has_key = has_key || !keys.is_empty();
40-
let Some(resolvable_key) = keys.iter().find(|key| !key.arguments.is_empty()) else {
40+
let federation_spec_definition = subgraph.metadata().federation_spec_definition();
41+
let Some(resolvable_key) = keys.iter().find(|key| {
42+
federation_spec_definition
43+
.key_directive_arguments(key)
44+
.map(|args| args.resolvable)
45+
.unwrap_or(true) // @key(resolvable:) defaults to true in its definition
46+
}) else {
4147
continue;
4248
};
4349
let implementations_in_subgraph = subgraph

apollo-federation/tests/composition/compose_interface_object.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,54 @@ fn interface_object_with_inaccessible_field() {
543543
"id field should have @join__field for subgraph-c"
544544
);
545545
}
546+
547+
#[test]
548+
fn interface_with_non_resolvable_key_does_not_require_all_implementations() {
549+
// subgraphA defines the interface with a resolvable key and all implementations
550+
let subgraph_a = ServiceDefinition {
551+
name: "subgraphA",
552+
type_defs: r#"
553+
type Query {
554+
iFromA: I
555+
}
556+
557+
interface I @key(fields: "id") {
558+
id: ID!
559+
x: Int
560+
}
561+
562+
type A implements I @key(fields: "id") {
563+
id: ID!
564+
x: Int
565+
}
566+
567+
type B implements I @key(fields: "id") {
568+
id: ID!
569+
x: Int
570+
}
571+
572+
type C implements I @key(fields: "id") {
573+
id: ID!
574+
x: Int
575+
}
576+
"#,
577+
};
578+
579+
// subgraphB defines the interface with a non-resolvable key but does not
580+
// define the implementations
581+
let subgraph_b = ServiceDefinition {
582+
name: "subgraphB",
583+
type_defs: r#"
584+
interface I @key(fields: "id", resolvable: false) {
585+
id: ID!
586+
x: Int
587+
}
588+
"#,
589+
};
590+
591+
let result = compose_as_fed2_subgraphs(&[subgraph_a, subgraph_b]);
592+
// This should not error because a non-resolvable key doesn't require all implementations
593+
let _supergraph = result.expect(
594+
"Expected composition to succeed - non-resolvable interface key should not require all implementations"
595+
);
596+
}

0 commit comments

Comments
 (0)