Handle list merging
This commit is contained in:
parent
509a6f12b9
commit
63d8a3d1a0
2 changed files with 74 additions and 12 deletions
|
@ -203,12 +203,22 @@ mod merge_parallel_inline_fragments {
|
||||||
use types::scalars::EmptyMutation;
|
use types::scalars::EmptyMutation;
|
||||||
|
|
||||||
struct Type;
|
struct Type;
|
||||||
|
struct Other;
|
||||||
|
|
||||||
graphql_object!(Type: () |&self| {
|
graphql_object!(Type: () |&self| {
|
||||||
field a() -> &str { "Apple" }
|
field a() -> &str { "Apple" }
|
||||||
field b() -> &str { "Banana" }
|
field b() -> &str { "Banana" }
|
||||||
field c() -> &str { "Cherry" }
|
field c() -> &str { "Cherry" }
|
||||||
field deep() -> Type { Type }
|
field deep() -> Type { Type }
|
||||||
|
field other() -> Vec<Other> { vec![Other, Other] }
|
||||||
|
});
|
||||||
|
|
||||||
|
graphql_object!(Other: () |&self| {
|
||||||
|
field a() -> &str { "Apple" }
|
||||||
|
field b() -> &str { "Banana" }
|
||||||
|
field c() -> &str { "Cherry" }
|
||||||
|
field deep() -> Type { Type }
|
||||||
|
field other() -> Vec<Other> { vec![Other, Other] }
|
||||||
});
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -218,15 +228,24 @@ mod merge_parallel_inline_fragments {
|
||||||
{ a, ...FragOne }
|
{ a, ...FragOne }
|
||||||
fragment FragOne on Type {
|
fragment FragOne on Type {
|
||||||
b
|
b
|
||||||
deep {
|
deep: deep {
|
||||||
b
|
b
|
||||||
deeper: deep { b }
|
deeper: other {
|
||||||
|
deepest: deep {
|
||||||
|
b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
... on Type {
|
... on Type {
|
||||||
c
|
c
|
||||||
deeper: deep { c }
|
deeper: other {
|
||||||
|
deepest: deep {
|
||||||
|
c
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c
|
c
|
||||||
}";
|
}";
|
||||||
|
|
||||||
|
@ -251,12 +270,37 @@ mod merge_parallel_inline_fragments {
|
||||||
("b", Value::string("Banana")),
|
("b", Value::string("Banana")),
|
||||||
(
|
(
|
||||||
"deeper",
|
"deeper",
|
||||||
Value::object(
|
Value::list(
|
||||||
vec![
|
vec![
|
||||||
("b", Value::string("Banana")),
|
Value::object(
|
||||||
("c", Value::string("Cherry")),
|
vec![
|
||||||
].into_iter()
|
(
|
||||||
.collect(),
|
"deepest",
|
||||||
|
Value::object(
|
||||||
|
vec![
|
||||||
|
("b", Value::string("Banana")),
|
||||||
|
("c", Value::string("Cherry")),
|
||||||
|
].into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
].into_iter().collect()
|
||||||
|
),
|
||||||
|
Value::object(
|
||||||
|
vec![
|
||||||
|
(
|
||||||
|
"deepest",
|
||||||
|
Value::object(
|
||||||
|
vec![
|
||||||
|
("b", Value::string("Banana")),
|
||||||
|
("c", Value::string("Cherry")),
|
||||||
|
].into_iter()
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
].into_iter().collect()
|
||||||
|
),
|
||||||
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
("c", Value::string("Cherry")),
|
("c", Value::string("Cherry")),
|
||||||
|
|
|
@ -505,11 +505,29 @@ fn is_excluded(directives: &Option<Vec<Spanning<Directive>>>, vars: &Variables)
|
||||||
|
|
||||||
fn merge_key_into(result: &mut OrderMap<String, Value>, response_name: &str, value: Value) {
|
fn merge_key_into(result: &mut OrderMap<String, Value>, response_name: &str, value: Value) {
|
||||||
match result.entry(response_name.to_owned()) {
|
match result.entry(response_name.to_owned()) {
|
||||||
Entry::Occupied(mut e) => match (e.get_mut().as_mut_object_value(), value) {
|
Entry::Occupied(mut e) => {
|
||||||
(Some(dest_obj), Value::Object(src_obj)) => {
|
match e.get_mut() {
|
||||||
merge_maps(dest_obj, src_obj);
|
&mut Value::Object(ref mut dest_obj) => {
|
||||||
|
if let Value::Object(src_obj) = value {
|
||||||
|
merge_maps(dest_obj, src_obj);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
&mut Value::List(ref mut dest_list) => {
|
||||||
|
if let Value::List(src_list) = value {
|
||||||
|
dest_list.iter_mut().zip(src_list.into_iter()).for_each(|(d, s)| {
|
||||||
|
match d {
|
||||||
|
&mut Value::Object(ref mut d_obj) => {
|
||||||
|
if let Value::Object(s_obj) = s {
|
||||||
|
merge_maps(d_obj, s_obj);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
},
|
},
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
e.insert(value);
|
e.insert(value);
|
||||||
|
|
Loading…
Reference in a new issue