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

Resolve ambiguous null interpretation with regards to defaultValues #262

Closed
wants to merge 1 commit into from

Conversation

samsouder
Copy link

There is some ambiguity in both the GraphQL spec and various implementations with regards to when defaultValues are applied to arguments.

A spec change to resolve this is being considered and there is a proposed PR for the JS implementation as well.

I have run into this during use of graphql-php where I wanted defaultValue to be applied for an optional argument (which can't be null either), but the client used sends null as the value for the argument. I expected the defaultValue to be substituted, but null was the coerced value instead.

This PR tries to apply a similar fix for the ambiguity in the above PR for the JS implementation, always using the defaultValue for a node if the value is explicitly sent as null (either directly or via variables).

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 92.82% when pulling 658836c on samsouder:master into 94525c0 on webonyx:master.

@vladar
Copy link
Member

vladar commented Mar 29, 2018

I think we should wait for a fix in the reference implementation.

@nagledb
Copy link
Contributor

nagledb commented Nov 8, 2018

The reference implementation merged the referenced PR in April.

@simPod
Copy link
Collaborator

simPod commented Nov 12, 2018

Needs rebase tho

@SevInf
Copy link
Contributor

SevInf commented Nov 13, 2018

Also, i think spec and reference implementation changed since this PR. Explicit "null" don't sets value to default anymore.

/**
* @it when null value provided directly
*/
public function testWhenNullValueProvidedDirectly()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public function testWhenNullValueProvidedDirectly()
public function testWhenNullValueProvidedDirectly() : void

/**
* @it when null value variable provided
*/
public function testWhenNullValueVariableProvided()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public function testWhenNullValueVariableProvided()
public function testWhenNullValueVariableProvided() : void

fieldWithDefaultArgumentValue(input: $optional)
}');

$this->assertEquals(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$this->assertEquals(
self::assertEquals(

fieldWithDefaultArgumentValue(input: null)
}');

$this->assertEquals(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$this->assertEquals(
self::assertEquals(

@spawnia
Copy link
Collaborator

spawnia commented Jun 10, 2019

This looks like an important bugfix, especially considering that the reference implementation is now also fixed: graphql/graphql-js#1274

The spec definitely says that explicit null is not the same as omitting the argument: https://graphql.github.io/graphql-spec/draft/#sec-Null-Value

@vladar anything i can do to move this along?

@samsouder
Copy link
Author

I no longer have interest in fixing this specific issue to ensure it matches the current reference implementation.

@samsouder samsouder closed this Jun 11, 2019
@spawnia
Copy link
Collaborator

spawnia commented Jun 11, 2019

@vladar i would be willing to champion this and create a new PR, ok?

@vladar
Copy link
Member

vladar commented Jun 12, 2019

@spawnia Yeah, as long as it matches reference implementation and spec, sure.

@spawnia
Copy link
Collaborator

spawnia commented Aug 15, 2019

Fixed in bf4e7d4

@vladar Thanks for tackling this important issue. You are doing a great job with this library!

@vladar
Copy link
Member

vladar commented Aug 16, 2019

@spawnia thanks %)

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.

7 participants