From aaf8d14e58fe94ee5375391d33bc9ad6bcaa08e3 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 24 Mar 2023 11:05:02 +0100 Subject: [PATCH] chore(compiler): test for operation field type resolution v.s. type extensions (#492) This type resolution in https://github.com/apollographql/router/issues/2710 was the motivation to start work on https://github.com/apollographql/apollo-rs/issues/468 --- crates/apollo-compiler/src/database/hir.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/apollo-compiler/src/database/hir.rs b/crates/apollo-compiler/src/database/hir.rs index 49cfff65b..1d5b93d5a 100644 --- a/crates/apollo-compiler/src/database/hir.rs +++ b/crates/apollo-compiler/src/database/hir.rs @@ -3568,6 +3568,20 @@ mod tests { assert!(!union_.has_member("Enum")); } + #[test] + fn query_extended_type() { + let mut compiler = ApolloCompiler::new(); + compiler.add_type_system("type Query { foo: String }", "base.graphql"); + compiler.add_type_system("extend type Query { bar: Int }", "ext.graphql"); + compiler.add_executable("{ bar }", "query.graphql"); + let operations = compiler.db.all_operations(); + let fields = operations[0].fields(&compiler.db); + // This unwrap failed before https://github.com/apollographql/apollo-rs/pull/482 + // changed the behavior of `ObjectTypeDefinition::field(name)` in `hir_db::parent_ty` + let ty = fields[0].ty(&compiler.db).unwrap(); + assert_eq!(ty.name(), "Int"); + } + #[test] fn syntax_errors() { let mut compiler = ApolloCompiler::new();