-
-
Notifications
You must be signed in to change notification settings - Fork 553
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 depth limit validator #1021
Conversation
Thanks for adding the Here's a preview of the changelog: This release adds a query depth limit validation rule so that you can guard import strawberry
from strawberry.schema import default_validation_rules
from strawberry.tools import depth_limit_validator
# Add the depth limit validator to the list of default validation rules
validation_rules = (
default_validation_rules + [depth_limit_validator(3)]
)
result = schema.execute_sync(
"""
query MyQuery {
user {
pets {
owner {
pets {
name
}
}
}
}
}
""",
validation_rules=validation_rules,
)
)
assert len(result.errors) == 1
assert result.errors[0].message == "'MyQuery' exceeds maximum operation depth of 3" Here's the preview release card for twitter: Here's the tweet text:
|
Codecov Report
@@ Coverage Diff @@
## main #1021 +/- ##
==========================================
+ Coverage 97.43% 97.55% +0.11%
==========================================
Files 81 82 +1
Lines 3044 3110 +66
Branches 420 440 +20
==========================================
+ Hits 2966 3034 +68
+ Misses 44 42 -2
Partials 34 34 |
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.
Nice work, I'm very excited for this. I added a couple of small comments, just things that came to my mind :)
Thanks for the review @DoctorJohn , I'll get those changes in as soon as I can. |
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.
LGTM 👍
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.
💯
a5fec88
to
075d14e
Compare
075d14e
to
a576e16
Compare
a576e16
to
f81938e
Compare
Co-authored-by: Jonathan Ehwald <[email protected]>
a9680fc
to
19c6662
Compare
Description
Adds a python port of https://github.com/stems/graphql-depth-limit
Also allow passing custom validators to
execute_sync
andexecute
.Types of Changes
Issues Fixed or Closed by This PR
Checklist