Open
Conversation
add "ValidationRules" field to graphql.Params, to be able to customize validation rules per query.
to write custom validation rules, sometimes it want to access field's argument values, but getArgumentValues() is private. this creates public version of getArgumentValues() to access from those validation rules.
c67a102 to
64d8171
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ValidationRulefield tographql.Paramsand 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.SpecifiedRulesbecause other packages usegraphqlare 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.