New plugin: useExtendedValidation
and implementation of @oneOf
directive
#149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background for this plugin:
At the moment, the existing phases of the requests pipeline are consist of: parse, validate, contextBuilding, execute.
Variables parsing happens on a separate flow (as part of the request pipeline), and it's being provided to
execute
externally. Input coercion happens during execution, as an internal step. The implication of this is the fact that validation rules only have access to the AST of the documents (and to the validation context in general), but not to variables or execution params.Modern implementation often needs to access variables in order to provide a more complete validation phase.
To work around that, we can implement in
envelop
a plugin for extended validation. We follow the sameValidationRule
interface, with the addition ofExecutionArgs
provided. And Envelop makes sure to pass run that beforeexecute
runs.The flow is the same as
validate
and it uses the same visitors flow, but allows developers to write more simplified code, and do more enriched validations.As a simple example for this POC, I implemented the basics of this plugin and also implemented
@oneOf
directive for adding support for input unions.More ideas that we might be able to implement:
field: String @max(5)
.field: String! @authorization(role: "test")
.This might also introduce another way of doing directive-based validations, since it does not require composing resolvers.