From b07dc12b66f1d2eb77d07cdf76781926fbc291ca Mon Sep 17 00:00:00 2001 From: David Overton Date: Tue, 19 Mar 2024 18:23:01 +1100 Subject: [PATCH] Fix for unifying object types --- crates/cli/src/introspection/sampling.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/cli/src/introspection/sampling.rs b/crates/cli/src/introspection/sampling.rs index 5b0e4e61..8e86fb77 100644 --- a/crates/cli/src/introspection/sampling.rs +++ b/crates/cli/src/introspection/sampling.rs @@ -48,7 +48,11 @@ async fn sample_schema_from_collection( let mut collected_object_types = vec![]; while let Some(document) = cursor.try_next().await? { let object_types = make_object_type(collection_name, &document)?; - collected_object_types = unify_object_types(collected_object_types, object_types)?; + collected_object_types = if collected_object_types.is_empty() { + object_types + } else { + unify_object_types(collected_object_types, object_types)? + }; } let collection_info = Collection { name: collection_name.to_string(), @@ -124,7 +128,11 @@ fn make_field_type( for elem in arr { let (elem_collected_otds, elem_type) = make_field_type(object_type_name, field_name, elem)?; - collected_otds = unify_object_types(collected_otds, elem_collected_otds)?; + collected_otds = if collected_otds.is_empty() { + elem_collected_otds + } else { + unify_object_types(collected_otds, elem_collected_otds)? + }; let context = TypeUnificationContext::new(object_type_name, field_name); result_type = unify_type(context, result_type, elem_type)?; }