Fix CoerceArgumentValues() hasValue#1056
Merged
leebyron merged 3 commits intographql:mainfrom Jul 3, 2025
Merged
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
The latest build of GraphQL.NET does not suffer from this issue either. Test added in graphql-dotnet/graphql-dotnet#3762 to be sure. |
d7ff2cb to
47e4904
Compare
Shane32
approved these changes
Jan 9, 2025
martinbonnin
approved these changes
Jan 10, 2025
Contributor
|
After checking against GraphQL JS this looks to be in line with how it's done there |
BoD
approved these changes
Jun 26, 2025
leebyron
pushed a commit
that referenced
this pull request
Jul 3, 2025
An alternative to #1056 which fully removes the `hasValue` variable in favor of hopefully more clear conditions
leebyron
pushed a commit
that referenced
this pull request
Jul 3, 2025
An alternative to #1056 which fully removes the `hasValue` variable in favor of hopefully more clear conditions
leebyron
pushed a commit
that referenced
this pull request
Jul 3, 2025
An alternative to #1056 which fully removes the `hasValue` variable in favor of hopefully more clear conditions
Collaborator
|
I'll likely suggestion continuing this, but while reviewing thought that we might want to consider the next step in removing this "hasValue" concept altogether: #1178 |
mjmahone
approved these changes
Jul 3, 2025
23 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug discovered whilst carefully evaluating
CoerceArgumentValues()that leads to "undefined value leakage" and potential null pointer exception if strictly following the spec. GraphQL.js does not suffer this, so this is a spec bug rather than an implementation bug.Consider the following schema:
And the following GraphQL query:
Imagine that we send an empty object (
{}) as the variable values.Coercing the variableValues according to https://spec.graphql.org/draft/#CoerceVariableValues() we get an empty object (
{}).Fast-forward to https://spec.graphql.org/draft/#CoerceArgumentValues():
coercedValues = {}argumentValues = { arg: $var }fieldName = 'field'field named {fieldName}.
argumentDefinitions = { arg: String! = "defaultValue" }argumentName = 'arg'argumentType = String!defaultValue = 'defaultValue'{argumentName}. 🐛 !!!BUG!!!
hasValue = truebecauseargumentValuesdoes provide the variable$varas the value for the argument 'arg'{argumentName}.
argumentValue = $varYes, $var is a variablevariableName = 'var'{variableName}. 🐛 !!!BUG!!! This does not fire, but
hasValueis already {true} by the above.{variableName}. 🐛 !!!BUG!!!
value = undefinedNOT TRIGGEREDNOT TRIGGEREDsince hasValue is true{defaultValue}.
not {true} or {value} is {null}, raise a field error.
NOT TRIGGEREDbecausehasValueis {true} and value is not {null} (it is undefined!)Yes, it isIt is not, it is undefined{null}.
It is!{value}.
coercedValues[argumentName] = undefined(sincevalueis undefined){argumentType}, raise a field error.
input coercion rules of {argumentType}.
{coercedValue}.
Expectation:
coercedValues = { arg: "defaultValue" }Actual result:
coercedValues = { arg: undefined }argis non-null string -> NPE! 💥Essentially the phrase "Let {hasValue} be {true} if {argumentValues} provides a value for the name {argumentName}" is at best ambiguous and at worst plain wrong, since the next two lines get the "value" for {argumentName} and then check to see if this {value} is a variable.
This PR fixes this issue by only setting
hasValuetotruewhen the value is explicitly resolved via the two branches: variable and non-variable.There is no need for a GraphQL.js PR for this since GraphQL.js already follows the expected behavior; reproduction: