Skip to content
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

Closed

Conversation

laststylebender14
Copy link
Contributor

@laststylebender14 laststylebender14 commented Jul 26, 2024

Summary:
Briefly describe the changes made in this PR.

Issue Reference(s):
Fixes #... (Replace "..." with the issue number)

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • PR follows the naming convention of <type>(<optional scope>): <title>

@laststylebender14 laststylebender14 marked this pull request as draft July 26, 2024 12:11
@laststylebender14 laststylebender14 marked this pull request as ready for review July 26, 2024 13:07
@laststylebender14 laststylebender14 marked this pull request as draft July 26, 2024 14:46
@@ -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() {
Copy link
Contributor

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

Comment on lines +128 to +131
} else {
Err(ValidationError::ValueRequired.into())
.map_err(|e| self.to_location_error(e, node, data_path))
}
Copy link
Contributor

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() {
Copy link
Contributor

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?

Comment on lines +256 to +257
path.push(PathSegment::Index(data_path[idx]));
idx += 1;
Copy link
Contributor

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

Comment on lines +9 to +10
users: [User] @http(path: "/users")
posts: [Post] @http(path: "/posts")
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foo: [Foo]! @http(path: "/foos")
foos: [Foo]! @http(path: "/foos")

tests/execution/test-required-fields.md Outdated Show resolved Hide resolved
post: Post! @http(path: "/posts/12")
foo: [Foo]! @http(path: "/foos")
fooInner: [Foo!] @http(path: "/foos-inner")
}
Copy link
Contributor

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!]!

tests/execution/test-required-fields.md Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Aug 3, 2024

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Aug 3, 2024
Base automatically changed from fix/handle-gql-errors to refactor/enum-validation-conflict-fixes August 11, 2024 05:38
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Aug 11, 2024
Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Aug 16, 2024
Base automatically changed from refactor/enum-validation-conflict-fixes to main August 17, 2024 07:06
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Aug 17, 2024
Copy link

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Aug 22, 2024
@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Aug 23, 2024
@karatakis
Copy link
Contributor

I will continue the development of this PR

@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Aug 23, 2024
@karatakis
Copy link
Contributor

Because this PR has been stale for too long, I ported the changes to the current main branch. See here #2754

@meskill
Copy link
Contributor

meskill commented Aug 27, 2024

in favor of #2754

@meskill meskill closed this Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: test-jit Run all integration tests for the JIT optimized engine type: fix Iterations on existing features or infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants