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

Add support for custom validators in default GraphQL backend #267

Open
JoaRiski opened this issue Feb 25, 2020 · 0 comments · May be fixed by #268
Open

Add support for custom validators in default GraphQL backend #267

JoaRiski opened this issue Feb 25, 2020 · 0 comments · May be fixed by #268

Comments

@JoaRiski
Copy link

JoaRiski commented Feb 25, 2020

The default GraphQL backend seems to perform validation prior to execution of a query. The validators that are being run are statically defined in https://github.com/graphql-python/graphql-core/blob/fe703f0d176c78b205d2abf929193f1e910fe4a0/graphql/validation/rules/__init__.py#L32-L57 and there doesn't seem to be a very good way to add custom validators to this list.

It would be nice to be able to extend the default GraphQL backend with your own validators, e.g. by having a overridable function called get_validators in the backend class that's used for getting the validators.

Right now the only option (as far as I'm aware) seems to be to completely re-implement the execution and validation logic if you don't want to monkeypatch the validators list.

JoaRiski added a commit to JoaRiski/graphql-core that referenced this issue Feb 25, 2020
Support extending the GraphQLCoreBackend class with custom validators by
adding a function \"get_validation_rules\" that can be overridden in
subclasses where needed.

This change in combination with setting the default graphql backend
allows for easy additions to validation rules. An example use case would
be if there's a need to perform query cost or depth analysis, one can
create a validator that restricts execution of the query based on it's
execution cost.

Of course this could also be used to remove validators if that is
necessary for some use case.

Resolves graphql-python#267
JoaRiski added a commit to JoaRiski/graphql-core that referenced this issue Feb 25, 2020
Support extending the GraphQLCoreBackend class with custom validators by
adding a function "get_validation_rules" that can be overridden in
subclasses where needed.

This change in combination with setting the default graphql backend
allows for easy additions to validation rules. An example use case would
be if there's a need to perform query cost or depth analysis, one can
create a validator that restricts execution of the query based on it's
execution cost.

Of course this could also be used to remove validators if that is
necessary for some use case.

Resolves graphql-python#267
@JoaRiski JoaRiski linked a pull request Feb 25, 2020 that will close this issue
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 a pull request may close this issue.

1 participant