Skip to content

fix(validator): allow nullable variables for nonnull args with default#396

Merged
StevenACoffman merged 1 commit intovektah:masterfrom
lbarthon:lbarthonet/default-value-args
Oct 30, 2025
Merged

fix(validator): allow nullable variables for nonnull args with default#396
StevenACoffman merged 1 commit intovektah:masterfrom
lbarthon:lbarthonet/default-value-args

Conversation

@lbarthon
Copy link
Copy Markdown
Contributor

@lbarthon lbarthon commented Oct 29, 2025

The validation was failing for arguments that are defined as required, but have a default value, preventing a non-required argument to override their value, while it should work as expected.

Given the tests are imported from JS, I'm not sure how to add a new one there. Here's an example schema and query to reproduce this:

type Query {
  user(username: String! = "foo"): User
}

type User {
  username: String!
}
query Foo($username: String) {
  user(username: $username) {
    username
  }
}

I have:

  • Added tests covering the bug / feature
  • Updated any relevant documentation

The validation was failing for arguments that are defined as required, but have
a default value, preventing a non-required argument to override their value,
while it should work as expected.

Given the tests are imported from JS, I'm not sure how to add a new one there.
Here's an example schema and query to reproduce this:
```
type Query {
  user(username: String! = "foo"): User
}

type User {
  username: String!
}
```

```
query Foo($username: String) {
  user(username: $username) {
    username
  }
}
```
@lbarthon
Copy link
Copy Markdown
Contributor Author

Hey @StevenACoffman! Would you mind having a look at this?
We rely on that for gqlgen, would be great to have it bumped there too, once we land this 😁

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 87.549% (-0.03%) from 87.575%
when pulling 6bd0682 on lbarthon:lbarthonet/default-value-args
into 1bb503e on vektah:master.

@StevenACoffman StevenACoffman merged commit 5b41269 into vektah:master Oct 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants