-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: raise validation error for required fields #2535
fix: raise validation error for required fields #2535
Conversation
@@ -82,7 +82,12 @@ impl<'a, Value: JsonLike<'a> + Clone + 'a> Synth<Value> { | |||
match parent { | |||
Some(parent) => { | |||
if !Self::is_array(&node.type_of, parent) { | |||
return Ok(Value::null()); | |||
if node.type_of.is_nullable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's put this link https://spec.graphql.org/October2021/#sec-Handling-Field-Errors somewhere around this code so it's faster to check the spec
} else { | ||
Err(ValidationError::ValueRequired.into()) | ||
.map_err(|e| self.to_location_error(e, node, data_path)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just move that check at the end of the function and do it only once?
i.e. store the ouput in variable and check if shouldn't be null
// IR exists, so there must be a value. | ||
// if there is no value then we must return Null | ||
Ok(Value::null()) | ||
if node.type_of.is_nullable() || node.ir.is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to check ir here? Why having ir allows to have null for possibly non-nullable field?
path.push(PathSegment::Index(data_path[idx])); | ||
idx += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code travels from children to parent fields to build the path, so it's built in backward, but the data_path
is built in forward. So here you'll probably using the wrong indexes in case we have lists inside lists. Need a test for this
users: [User] @http(path: "/users") | ||
posts: [Post] @http(path: "/posts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, check the spec.
Seems like, since the field posts
is nullable it should be set to null instead of propagating up to the whole data
users: [User] @http(path: "/users") | ||
posts: [Post] @http(path: "/posts") | ||
post: Post! @http(path: "/posts/12") | ||
foo: [Foo]! @http(path: "/foos") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foo: [Foo]! @http(path: "/foos") | |
foos: [Foo]! @http(path: "/foos") |
post: Post! @http(path: "/posts/12") | ||
foo: [Foo]! @http(path: "/foos") | ||
fooInner: [Foo!] @http(path: "/foos-inner") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add test case for [Foo!]!
Action required: PR inactive for 5 days. |
Action required: PR inactive for 5 days. |
Action required: PR inactive for 5 days. |
Co-authored-by: Kiryl Mialeshka <[email protected]>
I will continue the development of this PR |
Because this PR has been stale for too long, I ported the changes to the current main branch. See here #2754 |
in favor of #2754 |
Summary:
Briefly describe the changes made in this PR.
Issue Reference(s):
Fixes #... (Replace "..." with the issue number)
Build & Testing:
cargo test
successfully../lint.sh --mode=fix
to fix all linting issues raised by./lint.sh --mode=check
.Checklist:
<type>(<optional scope>): <title>