-
Notifications
You must be signed in to change notification settings - Fork 769
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 validation rules #1475
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach LGTM! Maybe worth a quick mention in some docs/ file about how to specify validation_rules
? And a quick test seems worthwhile before merging.
Thanks for adding this! 🎉
@firaskafri should we release another patch version (v3.1.6) before merging this? I think this deserves a minor bump to v3.2.0 but there were a couple of small bug fixing PRs merged since v3.1.5 so I think it's a good idea to have another patch version for v3.1. |
dfbb8bf
to
8eeffc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Awesome stuff! Really appreciate the clear docs examples and tests!
Agreed with your suggestion that we should release another patch version (v3.1.6) before merging this and releasing this as a minor bump to 3.2.0
def test_validation_disallow_introspection(client, url): | ||
response = client.post(url_string(url, query="{__schema {queryType {name}}}")) | ||
|
||
assert response.status_code == 400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we also check that the json representation of the response
does not contain the __schema
in its data (or data is null/empty, however it appears in practice)? That way we ensure it's not merely returning a 400 and the error message, but is also omitting the introspection data from the response as intended. (Same goes for the other 400 error tests below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, testing it locally with another approach I used to have
@pmcarlos Would you be able to share your current method? This PR is to be merged eventually but there's someone in Graphene Discord asking if there's another way to disable introspection. |
Hi guys, any idea when this PR will be merged ? |
This would be part of the |
Hello @kiendang not at all. |
@firaskafri Awesome. Thanks! We're good to go for |
Hi @kiendang any example on how to implement both rules ? I tried to follow the graphene documentation:
But I get an error |
@lee-pai-long hmm that's weird. It comes with Graphene. We have a test for it in this repo and it works fine. You can try taking a look at your installed packages? Alternatively the introspection disabling rule is also implemented in from graphql.validation.rules.custom.no_schema_introspection import NoSchemaIntrospectionCustomRule
|
Hi @kiendang thanks for you help, actually my error was that I didn't have the right version of |
* Add support for validation rules * Enable customizing validate max_errors through settings * Add tests for validation rules * Add examples for validation rules * Allow setting validation_rules in class def * Add tests for validation_rules inherited from parent class * Make tests for validation rules stricter
Close #1472
Close #1342