Open benjie opened 1 year ago
Name | Link |
---|---|
Latest commit | 47e49041ebcadf43392100ee2c9a8b6ed4ac51e4 |
Latest deploy log | https://app.netlify.com/sites/graphql-spec-draft/deploys/6748af62ae812f0008d324d8 |
Deploy Preview | https://deploy-preview-1056--graphql-spec-draft.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
GraphQL.js does not suffer this, so this is a spec bug rather than an implementation bug.
The latest build of GraphQL.NET does not suffer from this issue either. Test added in https://github.com/graphql-dotnet/graphql-dotnet/pull/3762 to be sure.
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'
argumentDefinitions = { arg: String! = "defaultValue" }
argumentName = 'arg'
argumentType = String!
defaultValue = 'defaultValue'
hasValue = true
becauseargumentValues
does provide the variable$var
as the value for the argument 'arg'argumentValue = $var
Yes, $var is a variable
variableName = 'var'
hasValue
is already {true} by the above.value = undefined
NOT TRIGGERED
NOT TRIGGERED
since hasValue is trueNOT TRIGGERED
becausehasValue
is {true} and value is not {null} (it is undefined!)Yes, it is
It is not, it is undefined
It is!
coercedValues[argumentName] = undefined
(sincevalue
is undefined)Expectation:
coercedValues = { arg: "defaultValue" }
Actual result:coercedValues = { arg: undefined }
arg
is non-null string -> NPE! :boom: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
hasValue
totrue
when 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: