From e9efad44795f9cfd206dc33cd2934ef56c770b5e Mon Sep 17 00:00:00 2001 From: Sunli Date: Sun, 27 Sep 2020 18:49:04 +0800 Subject: [PATCH] Fix the problem when generating Federation SDL. #283 --- src/registry/export_sdl.rs | 10 ++++++++-- src/registry/mod.rs | 1 - src/schema.rs | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/registry/export_sdl.rs b/src/registry/export_sdl.rs index 6dccdb76..6ece1758 100644 --- a/src/registry/export_sdl.rs +++ b/src/registry/export_sdl.rs @@ -115,8 +115,14 @@ impl Registry { description, .. } => { - if name == &self.query_type && self.is_empty_query { - return; + if name == &self.query_type { + if federation && fields.len() <= 4 { + // Is empty query root, only __schema, __type, _service, _entities fields + return; + } else if !federation && fields.len() <= 2 { + // Is empty query root, only __schema, __type + return; + } } if let Some(subscription_type) = &self.subscription_type { diff --git a/src/registry/mod.rs b/src/registry/mod.rs index 9d5a69d4..d4988a95 100644 --- a/src/registry/mod.rs +++ b/src/registry/mod.rs @@ -257,7 +257,6 @@ pub struct Registry { pub directives: HashMap, pub implements: HashMap>, pub query_type: String, - pub is_empty_query: bool, pub mutation_type: Option, pub subscription_type: Option, } diff --git a/src/schema.rs b/src/schema.rs index dd774bce..7a9cbab0 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -214,12 +214,11 @@ where } } - fn create_registry() -> Registry { + pub fn create_registry() -> Registry { let mut registry = Registry { types: Default::default(), directives: Default::default(), implements: Default::default(), - is_empty_query: Query::is_empty(), query_type: Query::type_name().to_string(), mutation_type: if Mutation::is_empty() { None