Fix merging parallel inline fragments

This commit is contained in:
Carlos Diaz-Padron 2018-02-18 14:40:04 -08:00 committed by theduke
parent 28763a5639
commit 509a6f12b9
2 changed files with 76 additions and 1 deletions

View file

@ -197,6 +197,81 @@ mod merge_parallel_fragments {
}
}
mod merge_parallel_inline_fragments {
use value::Value;
use schema::model::RootNode;
use types::scalars::EmptyMutation;
struct Type;
graphql_object!(Type: () |&self| {
field a() -> &str { "Apple" }
field b() -> &str { "Banana" }
field c() -> &str { "Cherry" }
field deep() -> Type { Type }
});
#[test]
fn test() {
let schema = RootNode::new(Type, EmptyMutation::<()>::new());
let doc = r"
{ a, ...FragOne }
fragment FragOne on Type {
b
deep {
b
deeper: deep { b }
... on Type {
c
deeper: deep { c }
}
}
c
}";
let vars = vec![].into_iter().collect();
let (result, errs) = ::execute(doc, None, &schema, &vars, &()).expect("Execution failed");
assert_eq!(errs, []);
println!("Result: {:?}", result);
assert_eq!(
result,
Value::object(
vec![
("a", Value::string("Apple")),
("b", Value::string("Banana")),
(
"deep",
Value::object(
vec![
("b", Value::string("Banana")),
(
"deeper",
Value::object(
vec![
("b", Value::string("Banana")),
("c", Value::string("Cherry")),
].into_iter()
.collect(),
),
),
("c", Value::string("Cherry")),
].into_iter()
.collect(),
),
),
("c", Value::string("Cherry")),
].into_iter()
.collect()
)
);
}
}
mod threads_context_correctly {
use value::Value;
use types::scalars::EmptyMutation;

View file

@ -455,7 +455,7 @@ where
if let Ok(Value::Object(mut hash_map)) = sub_result {
for (k, v) in hash_map.drain(..) {
result.insert(k, v);
merge_key_into(result, &k, v);
}
} else if let Err(e) = sub_result {
sub_exec.push_error_at(e, start_pos.clone());