Skip to content

Fix input coercion to allow null-valued Enums as arguments #848

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

Merged
merged 2 commits into from
May 18, 2017

Conversation

exogen
Copy link
Contributor

@exogen exogen commented May 13, 2017

This fixes the issue pointed out in #840 where null-valued Enums (supported since 0.9.5) were rejected when provided as arguments.

This reveals some minor code duplication in isValidLiteralValue and valueFromAST.

There are likely other places in the code where null-valued Enums cause problems. To use one example: in isValidJSValue, if a type is GraphQLNonNull(EnumWithNullValue), then null should probably be accepted, since it represents a valid value within the Enum and is thus not really null (more generally, it should probably ask the ofType to serialize() the value first and check to see if that is null). But I didn't attempt to chase down all those edge cases; these changes are enough to get my test suite passing again.

Fixes #840.

@exogen
Copy link
Contributor Author

exogen commented May 13, 2017

Add higher level tests, for ArgumentsOfCorrectType specifically.

// null or invalid values represent a failure to parse correctly,
// in which case no value is returned.
if (type instanceof GraphQLEnumType ?
!type.serialize(parsed) : isNullish(parsed)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm this condition is a little gross now. I wonder if we should instead have something like type.isValidValue() or something along those lines to simplify this?

@leebyron leebyron merged commit ff845f7 into graphql:master May 18, 2017
@leebyron
Copy link
Contributor

Thanks for this! Always great to see regression tests added. I will look into an improvement to the conditional

leebyron added a commit that referenced this pull request May 18, 2017
Used for more semantically correct validity checking after #848
leebyron added a commit that referenced this pull request May 18, 2017
)

Used for more semantically correct validity checking after #848
@exogen exogen deleted the fix-null-enum-input-coercion branch May 19, 2017 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for null Enum values in 0.9.5 does not work for arguments
3 participants