fix some bug

This commit is contained in:
sunli 2020-03-09 09:33:36 +08:00
parent 0477ea1dd7
commit ce3d4cbc33
3 changed files with 11 additions and 10 deletions

View File

@ -14,6 +14,10 @@ pub fn is_valid_input_value(registry: &Registry, type_name: &str, value: &Value)
_ => false,
},
TypeInfo::Type(type_name) => {
if let Value::Null = value {
return true;
}
if let Some(ty) = registry.types.get(type_name) {
match ty {
Type::Scalar { is_valid, .. } => is_valid(value),
@ -24,12 +28,9 @@ pub fn is_valid_input_value(registry: &Registry, type_name: &str, value: &Value)
Type::InputObject { input_fields, .. } => match value {
Value::Object(values) => {
for field in input_fields {
if !is_valid_input_value(
registry,
&field.ty,
values.get(field.name).unwrap_or(&Value::Null),
) {
return false;
let value = values.get(field.name).unwrap_or(&Value::Null);
if !is_valid_input_value(registry, &field.ty, value) {
return field.default_value.is_some();
}
}
true

View File

@ -75,7 +75,7 @@ pub async fn test_input_object_default_value() {
let schema = Schema::new(Root, GQLEmptyMutation);
let query = format!(
r#"{{
a(input:{{e:null}}) {{
a(input:{{e:777}}) {{
a b c d e
}}
}}"#
@ -88,7 +88,7 @@ pub async fn test_input_object_default_value() {
"b": [1, 2, 3],
"c": "abc",
"d": 999,
"e": null,
"e": 777,
}
})
);

View File

@ -59,9 +59,9 @@ pub async fn test_optional_type() {
value2
value2_ref
test_arg1: test_arg(input: 10)
test_arg2: test_arg(input: null)
test_arg2: test_arg
test_input1: test_input(input: {{value: 10}})
test_input2: test_input(input: {{value: null}})
test_input2: test_input(input: {{}})
}}"#
);
assert_eq!(