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.
This PR eases writing and using custom validation rules. It includes two changes:
graphql.Do()
be able to change validation rulesby adding
ValidationRule
field tographql.Params
and use it forgraphql.ValidateDocument()
graphql.getArgumentValues()
be accessible from other packagesby adding
graphql.GetArgumentValues()
as a wrapper of it.Background
I wrote a cost analysis package:koron-go/gqlcost for graphql-go/graphql as a validation rule.
(It is a port of pa-bru/graphql-cost-analysis)
I use two problematic hacky methods to write it:
modify
graphql.SpecifiedRules
(refer: koron-go/gqlcost:gqlcost.go#L19-L28)There are no ways to use custom validation rules with
graphql.Do()
currently.It is highly problematic to modify
graphql.SpecifiedRules
because other packages usegraphql
are affected by this.Copy pile of codes from graphql-go/graphql:values.go to just access field's argument values (refer: koron-go/gqlcost:values.go#L3-L5)
I found that there are some cases to want access field arguments value when writing validation rules.
cost-analysis package uses those to calculate cost with
multipliers
.graphql-go/graphql has a function to do it, but it is private and not exported.
It wil be great, if those functions are public for other packages which provides custom validation rules.
I want to resolve these problems by this PR.