fix some bug
This commit is contained in:
parent
e0ffe3faa8
commit
0169fd6122
|
@ -14,6 +14,10 @@ pub fn is_valid_input_value(registry: &Registry, type_name: &str, value: &Value)
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
TypeInfo::Type(type_name) => {
|
TypeInfo::Type(type_name) => {
|
||||||
|
if let Value::Null = value {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ty) = registry.types.get(type_name) {
|
if let Some(ty) = registry.types.get(type_name) {
|
||||||
match ty {
|
match ty {
|
||||||
Type::Scalar { is_valid, .. } => is_valid(value),
|
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 {
|
Type::InputObject { input_fields, .. } => match value {
|
||||||
Value::Object(values) => {
|
Value::Object(values) => {
|
||||||
for field in input_fields {
|
for field in input_fields {
|
||||||
if !is_valid_input_value(
|
let value = values.get(field.name).unwrap_or(&Value::Null);
|
||||||
registry,
|
if !is_valid_input_value(registry, &field.ty, value) {
|
||||||
&field.ty,
|
return field.default_value.is_some();
|
||||||
values.get(field.name).unwrap_or(&Value::Null),
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub async fn test_input_object_default_value() {
|
||||||
let schema = Schema::new(Root, GQLEmptyMutation);
|
let schema = Schema::new(Root, GQLEmptyMutation);
|
||||||
let query = format!(
|
let query = format!(
|
||||||
r#"{{
|
r#"{{
|
||||||
a(input:{{e:null}}) {{
|
a(input:{{e:777}}) {{
|
||||||
a b c d e
|
a b c d e
|
||||||
}}
|
}}
|
||||||
}}"#
|
}}"#
|
||||||
|
@ -88,7 +88,7 @@ pub async fn test_input_object_default_value() {
|
||||||
"b": [1, 2, 3],
|
"b": [1, 2, 3],
|
||||||
"c": "abc",
|
"c": "abc",
|
||||||
"d": 999,
|
"d": 999,
|
||||||
"e": null,
|
"e": 777,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,9 +59,9 @@ pub async fn test_optional_type() {
|
||||||
value2
|
value2
|
||||||
value2_ref
|
value2_ref
|
||||||
test_arg1: test_arg(input: 10)
|
test_arg1: test_arg(input: 10)
|
||||||
test_arg2: test_arg(input: null)
|
test_arg2: test_arg
|
||||||
test_input1: test_input(input: {{value: 10}})
|
test_input1: test_input(input: {{value: 10}})
|
||||||
test_input2: test_input(input: {{value: null}})
|
test_input2: test_input(input: {{}})
|
||||||
}}"#
|
}}"#
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user