Skip to content

nested nullable list validation bugfix #3599

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

Conversation

jbellenger
Copy link
Contributor

@jbellenger jbellenger commented May 17, 2024

When validating directive arguments that use nested list types, it looks like the validator does not allow nulls to be used in valid positions.

For example, given a type like [[String!]], it rejects the value [null].

After looking into this, it looks like #2001 added support for coercing singleton items into lists, but didn't handle null values. The relevant part of the spec is this:

If the value passed as an input to a list type is not a list and not the null value, then the result of input coercion is a list of size one.

This PR changes scalar-to-list coercion to allow null values in nested lists. A side effect of this is that the validation error Argument value is X', expected a list value. will never be raised.

@jbellenger jbellenger changed the title nested list validation bugfix nested nullable list validation bugfix May 17, 2024
@jbellenger jbellenger marked this pull request as ready for review May 17, 2024 12:04
"WEEKDAY" | '"somestr"' | format(EXPECTED_ENUM_MESSAGE, "StringValue")
"WEEKDAY" | 'SATURDAY' | format(MUST_BE_VALID_ENUM_VALUE_MESSAGE, "SATURDAY", "MONDAY,TUESDAY")
"UserInput" | '{ fieldNonNull: "str", fieldNonNull: "dupeKey" }' | format(DUPLICATED_KEYS_MESSAGE, "fieldNonNull")
"UserInput" | '{ fieldNonNull: "str", unknown: "field" }' | format(UNKNOWN_FIELDS_MESSAGE, "unknown", "UserInput")
"UserInput" | '{ fieldNonNull: "str", fieldArrayOfArray: ["ArrayInsteadOfArrayOfArray"] }' | format(EXPECTED_LIST_MESSAGE, "StringValue")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd appreciate a careful look at this change.

This test case, which provided a ["ArrayInsteadOfArrayOfArray"] value to a nested list [[String]] seemed to be incorrect because it assumed that a string value is not an allowed input for the inner list type. This seems explicitly allowed by this section of the spec.

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Thank you very much for this work

@bbakerman bbakerman added this pull request to the merge queue Jun 1, 2024
Merged via the queue into graphql-java:master with commit 4b27080 Jun 1, 2024
1 check passed
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.

3 participants