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

Input Value Validation #3086

Closed
wants to merge 1 commit into from
Closed

Input Value Validation #3086

wants to merge 1 commit into from

Conversation

leebyron
Copy link
Contributor

@leebyron leebyron commented May 13, 2021

Depends on #3065

Factors out input validation to reusable functions:

  • Introduces validateInputLiteral by extracting this behavior from ValuesOfCorrectTypeRule.
  • Introduces validateInputValue by extracting this behavior from coerceInputValue
  • Simplifies coerceInputValue to return early on validation error
  • Unifies error reporting between validateInputValue and validateInputLiteral, causing some error message strings to change, but error data (eg locations) are preserved.

These two parallel functions will be used to validate default values in #3049

Potentially breaking if you rely on the existing behavior of coerceInputValue to call a callback function, as the call signature has changed. GraphQL behavior should not change, though error messages are now slightly different.

@andimarek
Copy link
Contributor

@leebyron question: are you going to validate default argument values of Directive definitions and arguments of applied Directives too?

For example:

# custom Scalar
scalar CacheKey

directive @cached(
  key: CacheKey = {key: "DEFAULT", duration=1000}
) on FIELD_DEFINITION 

type Query {
  hello: String @cached(key: {key: "hello", duration = 500})
}

@leebyron
Copy link
Contributor Author

Yes both. Though one additional follow up might be necessary.

Arguments of applied directives in operations have always been validated in the ValuesOfCorrectType validator. In schema they never translate into something so they haven't been validated. This seems like an easy thing to fix.

Directive definition argument default value validation is in the RFC spec change and included in the last PR in this stack

@leebyron leebyron force-pushed the value-to-literal branch 3 times, most recently from 13d9314 to 30deb95 Compare June 1, 2021 22:11
@leebyron leebyron force-pushed the input-validation branch 2 times, most recently from 757931d to d1fbfb3 Compare June 1, 2021 22:34
@leebyron leebyron added the PR: breaking change 💥 implementation requires increase of "major" version number label Jun 1, 2021
Factors out input validation to reusable functions:

* Introduces `validateInputLiteral` by extracting this behavior from `ValuesOfCorrectTypeRule`.
* Introduces `validateInputValue` by extracting this behavior from `coerceInputValue`
* Simplifies `coerceInputValue` to return early on validation error
* Unifies error reporting between `validateInputValue` and `validateInputLiteral`, causing some error message strings to change, but error data (eg locations) are preserved.

These two parallel functions will be used to validate default values in #3049

Potentially breaking if you rely on the existing behavior of `coerceInputValue` to call a callback function, as the call signature has changed. GraphQL behavior should not change, though error messages are now slightly different.
yaacovCR added a commit that referenced this pull request Oct 18, 2024
[#3086 rebased on
main](#3086).

Depends on #3812 

@leebyron comments from original PR:

> Factors out input validation to reusable functions:
> 
> * Introduces `validateInputLiteral` by extracting this behavior from
`ValuesOfCorrectTypeRule`.
> * Introduces `validateInputValue` by extracting this behavior from
`coerceInputValue`
> * Simplifies `coerceInputValue` to return early on validation error
> * Unifies error reporting between `validateInputValue` and
`validateInputLiteral`, causing some error message strings to change,
but error data (eg locations) are preserved.
> 
> These two parallel functions will be used to validate default values
> 
> Potentially breaking if you rely on the existing behavior of
`coerceInputValue` to call a callback function, as the call signature
has changed. GraphQL behavior should not change, though error messages
are now slightly different.

Note: also breaking if you rely on the default callback function to
throw. Grossly similar behavior is available with
`validateInputValue()`.

Co-authored-by: Lee Byron <lee.byron@robinhood.com>
@yaacovCR
Copy link
Contributor

Merged rebased version of this PR as #3813.

@yaacovCR yaacovCR closed this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: breaking change 💥 implementation requires increase of "major" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants