Skip to content

default variable fixes#1376

Open
jbellenger wants to merge 3 commits intographql-rust:masterfrom
jbellenger:fix/non-null-variable-default-value
Open

default variable fixes#1376
jbellenger wants to merge 3 commits intographql-rust:masterfrom
jbellenger:fix/non-null-variable-default-value

Conversation

@jbellenger
Copy link
Copy Markdown

@jbellenger jbellenger commented Apr 26, 2026

Hi there! I'm the maintainer of graphql-conformance, which verifies spec conformance across the graphql ecosystem. I noticed that juniper has a couple of deviations from the spec and I thought I might be able to contribute a fix for one of the easy ones (see juniper's conformance page for other conformance gaps)

The issue addressed by this PR is that juniper rejects some allowed patterns with variables.

For example, this query is valid and should be executable with empty variables:

query ($var: Boolean! = true) {
  __typename @skip(if:$var)
}

Juniper rejects this query in 2 ways:

# default value is not allowed
ValidationError([RuleError {
  locations: [SourcePosition { index: 33, line: 1, col: 32 }],
  message: "Argument \"var\" has type \"Boolean!\" and is not nullable, so it can't have a default value"
}])

# value must be provided
ValidationError([RuleError {
  locations: [SourcePosition { index: 16, line: 1, col: 15 }],
  message: "Variable \"$var\" of required type \"Boolean!\" was not provided."
}])

Queries with this shape are allowed by these sections of the spec:

  • Section 5.8.5, which allows non-nullable variables to have a default (see also: this PR, which explicitly describes that this is supported, "All variables can now have default values ... Previously it was invalid to supply a default value with a non-null variable.")
  • Section 6.1.2 3g, which allows a variable to be unspecified in a request if it has a default

Finally, the combination of a non-nullable variable with default, plus an unspecified variable, is implemented by this graphql-js test case.

Thank you for considering this PR. I'm not familiar with this code-base or its conventions, so please feel free to point out any issue no matter how small. I went through the checklist in CONTRIBUTING.md, everything passed except for the make test.book which failed for me in master.

@jbellenger jbellenger changed the title Allow default values on non-Null variables in DefaultValuesOfCorrectType validation rule default variable fixes Apr 26, 2026
@jbellenger jbellenger marked this pull request as ready for review April 26, 2026 18:11
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.

1 participant