Skip to content

Commit

Permalink
fix kitchen sink by adding possible_interface back, we should verify …
Browse files Browse the repository at this point in the history
…whether this is a bug as a possible interface is also a possible type
  • Loading branch information
JoviDeCroock committed May 24, 2024
1 parent 2bdadb9 commit 2b2245e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ impl<'a> SchemaInterface<'a> {
}
}

/// Add a new [SchemaInterface] to the list that implements this [SchemaInterface]
pub fn add_possible_interface(&mut self, _ctx: &'a ASTContext, interface: &'a str) {
self.possible_interfaces.push(interface);
}

/// Get list of possible [SchemaInterface]s that implement this [SchemaInterface]
#[inline]
pub fn get_possible_interfaces(&self) -> Vec<'a, &'a str> {
Expand Down Expand Up @@ -283,7 +288,7 @@ impl<'a> SchemaPossibleTypes<'a> for SchemaInterface<'a> {
fn add_possible_type(&mut self, _ctx: &'a ASTContext, object: &'a str) {
self.possible_types.push(object);
}

/// Get list of possible [SchemaObject] types
#[inline]
fn get_possible_types(&self) -> Vec<'a, &'a str> {
Expand Down
5 changes: 5 additions & 0 deletions src/schema/sdl/parse_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ pub(super) struct SchemaInterfacePlaceholder<'a> {
pub fields: FieldDefinitions<'a>,
pub(crate) interfaces: Vec<'a, &'a str>,
pub(crate) possible_types: Vec<'a, &'a str>,
pub(crate) possible_interfaces: Vec<'a, &'a str>,
}

impl<'a> SchemaInterfacePlaceholder<'a> {
pub fn add_possible_type(&mut self, possible_type: &'a str) {
self.possible_types.push(possible_type);
}

pub fn add_possible_interface(&mut self, possible_type: &'a str) {
self.possible_interfaces.push(possible_type);
}
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
5 changes: 4 additions & 1 deletion src/schema/sdl/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ impl<'a> private::ParseFromCtx<'a> for Schema<'a> {
TypeDefinition::InterfaceTypeDefinition(i) => {
for interface in i.interfaces.iter() {
if let Some(TypeDefinition::InterfaceTypeDefinition(implemented_interface)) = type_defs.get_mut(interface) {
implemented_interface.add_possible_type(name);
// TODO: check whether this is the right way to go about it, might be an existing bug in
// the client-schema
implemented_interface.add_possible_interface(name);
}
}
},
Expand Down Expand Up @@ -410,6 +412,7 @@ impl<'a> private::ParseFromCtx<'a> for SchemaInterfacePlaceholder<'a> {
fields,
interfaces,
possible_types: Vec::new_in(&ctx.ast_ctx.arena),
possible_interfaces: Vec::new_in(&ctx.ast_ctx.arena),
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/schema/sdl/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ fn interface_type_definition() {
name: "MyInterface",
fields: FieldDefinitions { fields },
interfaces: Vec::new_in(&ctx.arena),
possible_interfaces: Vec::new_in(&ctx.arena),
possible_types: Vec::new_in(&ctx.arena),
},
);
Expand Down Expand Up @@ -718,10 +719,11 @@ fn kitchen_sink() {
let introspection: IntrospectionQuery = serde_json::from_str(&KITCHEN_SINK).unwrap();
let mut expected = introspection.build_client_schema(&ctx).clone();
for (key, _typ) in expected.types.clone().iter() {
if !key.starts_with("__") {
if key.starts_with("__") {
expected.types.remove(key);
}
}

let parsed = Schema::parse(&ctx, source).unwrap();
assert_eq!(parsed, &expected);
}
Expand Down

0 comments on commit 2b2245e

Please sign in to comment.