Skip to content

Commit 6ae8c6d

Browse files
authored
fix(query-planner, router): fix introspection for federation v1 supergraph (#526)
The consumer-facing schema was missing filtering for `enum core__Purpose`, `directive @core`, and `directive @join_owner`. This caused introspection errors due to failure to find other associated types.
1 parent 1790162 commit 6ae8c6d

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

lib/query-planner/src/consumer_schema/strip_schema_internals.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,42 @@ use graphql_parser::schema::*;
33

44
use crate::{
55
federation_spec::{
6-
definitions::{JoinFieldSetScalar, JoinGraphEnum, LinkImportScalar, LinkPurposeEnum},
6+
definitions::{
7+
CorePurposesEnum, JoinFieldSetScalar, JoinGraphEnum, LinkImportScalar, LinkPurposeEnum,
8+
},
79
directives::{
8-
InaccessibleDirective, JoinEnumValueDirective, JoinFieldDirective, JoinGraphDirective,
9-
JoinImplementsDirective, JoinTypeDirective, JoinUnionMemberDirective, LinkDirective,
10-
TagDirective,
10+
CoreDirective, InaccessibleDirective, JoinEnumValueDirective, JoinFieldDirective,
11+
JoinGraphDirective, JoinImplementsDirective, JoinTypeDirective,
12+
JoinUnionMemberDirective, LinkDirective, TagDirective,
1113
},
14+
join_owner::JoinOwnerDirective,
1215
},
1316
utils::schema_transformer::{SchemaTransformer, TransformedValue},
1417
};
1518

1619
// directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ENUM | ENUM_VALUE | SCALAR | INPUT_OBJECT | INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION
1720
pub(crate) struct StripSchemaInternals;
1821

19-
static DIRECTIVES_TO_STRIP: [&str; 9] = [
22+
static DIRECTIVES_TO_STRIP: [&str; 11] = [
2023
JoinTypeDirective::NAME,
2124
JoinEnumValueDirective::NAME,
2225
JoinFieldDirective::NAME,
2326
JoinImplementsDirective::NAME,
2427
JoinUnionMemberDirective::NAME,
2528
JoinGraphDirective::NAME,
29+
JoinOwnerDirective::NAME,
2630
LinkDirective::NAME,
2731
TagDirective::NAME,
2832
InaccessibleDirective::NAME,
33+
CoreDirective::NAME,
2934
];
3035

31-
static DEFINITIONS_TO_STRIP: [&str; 4] = [
36+
static DEFINITIONS_TO_STRIP: [&str; 5] = [
3237
LinkPurposeEnum::NAME,
3338
LinkImportScalar::NAME,
3439
JoinGraphEnum::NAME,
3540
JoinFieldSetScalar::NAME,
41+
CorePurposesEnum::NAME,
3642
];
3743

3844
impl StripSchemaInternals {

lib/query-planner/src/federation_spec/definitions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ pub struct JoinGraphEnum {}
2121
impl JoinGraphEnum {
2222
pub const NAME: &str = "join__Graph";
2323
}
24+
25+
pub struct CorePurposesEnum {}
26+
27+
impl CorePurposesEnum {
28+
pub const NAME: &str = "core__Purpose";
29+
}

lib/query-planner/src/federation_spec/directives.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ pub struct LinkDirective {}
1818
impl LinkDirective {
1919
pub const NAME: &str = "link";
2020
}
21+
22+
pub struct CoreDirective {}
23+
24+
impl CoreDirective {
25+
pub const NAME: &str = "core";
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use graphql_parser::schema::{Directive, Value};
2+
3+
use super::directives::FederationDirective;
4+
5+
#[derive(Debug, Clone, Eq, PartialEq, Default)]
6+
pub struct JoinOwnerDirective {
7+
pub graph_id: String,
8+
}
9+
10+
impl JoinOwnerDirective {
11+
pub const NAME: &str = "join__owner";
12+
}
13+
14+
impl FederationDirective for JoinOwnerDirective {
15+
fn directive_name() -> &'static str {
16+
Self::NAME
17+
}
18+
19+
fn parse(directive: &Directive<'_, String>) -> Self
20+
where
21+
Self: Sized,
22+
{
23+
let mut result = Self::default();
24+
25+
for (arg_name, arg_value) in &directive.arguments {
26+
if arg_name.eq("graph") {
27+
match arg_value {
28+
Value::String(value) => result.graph_id = value.clone(),
29+
Value::Enum(value) => result.graph_id = value.clone(),
30+
_ => {}
31+
}
32+
}
33+
}
34+
35+
result
36+
}
37+
}
38+
39+
impl Ord for JoinOwnerDirective {
40+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
41+
self.graph_id.cmp(&other.graph_id)
42+
}
43+
}
44+
45+
impl PartialOrd for JoinOwnerDirective {
46+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
47+
Some(self.cmp(other))
48+
}
49+
}

lib/query-planner/src/federation_spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub(crate) mod join_enum_value;
2121
pub(crate) mod join_field;
2222
pub(crate) mod join_graph;
2323
pub(crate) mod join_implements;
24+
pub(crate) mod join_owner;
2425
pub(crate) mod join_type;
2526
pub(crate) mod join_union;
2627

0 commit comments

Comments
 (0)