Skip to content

Commit a183415

Browse files
committed
fix
1 parent 07589a0 commit a183415

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/validation/rules/values_of_correct_type.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::{
1414

1515
use super::ValidationRule;
1616

17-
#[derive(Default)]
1817
pub struct ValuesOfCorrectType {}
1918

2019
impl ValuesOfCorrectType {
@@ -23,7 +22,10 @@ impl ValuesOfCorrectType {
2322
}
2423

2524
pub fn is_custom_scalar(&self, type_name: &str) -> bool {
26-
!matches!(type_name, "String" | "Int" | "Float" | "Boolean" | "ID")
25+
match type_name {
26+
"String" | "Int" | "Float" | "Boolean" | "ID" => false,
27+
_ => true,
28+
}
2729
}
2830

2931
pub fn validate_value(
@@ -35,7 +37,7 @@ impl ValuesOfCorrectType {
3537
if let Some(input_type) = visitor_context.current_input_type_literal() {
3638
let named_type = input_type.inner_type();
3739

38-
if let Some(type_def) = visitor_context.schema.type_by_name(named_type) {
40+
if let Some(type_def) = visitor_context.schema.type_by_name(&named_type) {
3941
if !type_def.is_leaf_type() {
4042
user_context.report_error(ValidationError {
4143
error_code: self.error_code(),
@@ -76,7 +78,12 @@ impl ValuesOfCorrectType {
7678
if let TypeDefinition::Enum(enum_type_def) = &type_def {
7779
match raw_value {
7880
Value::Enum(enum_value) => {
79-
if enum_type_def.values.iter().any(|v| v.name.eq(enum_value)) {
81+
if enum_type_def
82+
.values
83+
.iter()
84+
.find(|v| v.name.eq(enum_value))
85+
.is_none()
86+
{
8087
user_context.report_error(ValidationError {
8188
error_code: self.error_code(),
8289
message: format!(
@@ -143,10 +150,11 @@ impl<'a> OperationVisitor<'a, ValidationErrorContext> for ValuesOfCorrectType {
143150
});
144151

145152
object_value.keys().for_each(|field_name| {
146-
if input_object_def
153+
if (input_object_def
147154
.fields
148155
.iter()
149-
.any(|f| f.name.eq(field_name))
156+
.find(|f| f.name.eq(field_name)))
157+
.is_none()
150158
{
151159
user_context.report_error(ValidationError {
152160
error_code: self.error_code(),

0 commit comments

Comments
 (0)