Fix bug where non-null lists could contain null if errors were returned

This commit is contained in:
Magnus Hallin 2017-11-20 08:53:51 +01:00
parent 23105259de
commit c4ded5781d
2 changed files with 43 additions and 10 deletions

View file

@ -321,6 +321,28 @@ impl<'a> TypeType<'a> {
_ => None,
}
}
pub fn innermost_concrete(&self) -> &'a MetaType {
match *self {
TypeType::Concrete(t) => t,
TypeType::NonNull(ref n) | TypeType::List(ref n) => n.innermost_concrete(),
}
}
pub fn list_contents(&self) -> Option<&TypeType<'a>> {
match *self {
TypeType::List(ref n) => Some(n),
TypeType::NonNull(ref n) => n.list_contents(),
_ => None,
}
}
pub fn is_non_null(&self) -> bool {
match *self {
TypeType::NonNull(_) => true,
_ => false,
}
}
}
impl<'a> DirectiveType<'a> {

View file

@ -81,11 +81,7 @@ where
_: Option<&[Selection]>,
executor: &Executor<CtxT>,
) -> Value {
Value::list(
self.iter()
.map(|e| executor.resolve_into_value(info, e))
.collect(),
)
resolve_into_list(executor, info, self.iter())
}
}
@ -143,11 +139,7 @@ where
_: Option<&[Selection]>,
executor: &Executor<CtxT>,
) -> Value {
Value::list(
self.iter()
.map(|e| executor.resolve_into_value(info, e))
.collect(),
)
resolve_into_list(executor, info, self.iter())
}
}
@ -159,3 +151,22 @@ where
InputValue::list(self.iter().map(|v| v.to_input_value()).collect())
}
}
fn resolve_into_list<T: GraphQLType, I: Iterator<Item=T>>(executor: &Executor<T::Context>, info: &T::TypeInfo, iter: I) -> Value {
let stop_on_null = executor.current_type()
.list_contents().expect("Current type is not a list type")
.is_non_null();
let mut result = Vec::new();
for o in iter {
let value = executor.resolve_into_value(info, &o);
if stop_on_null && value.is_null() {
return value;
}
result.push(value);
}
Value::list(result)
}