-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve extensions error handling (#3217)
* Clarify names of test cases * Remove unnecessary except block * Handle exceptions raised within extension hooks * Adjust tests depending on previous behaviour * Make ruff happy :) * Lint * Add release file * chore: add tests for syntax errors on parser cache * Update test * Add # pragma: no cover * Fix graphql errors were unnecessarily wrapped * Restore test * Restore * Pending exceptions * Restore code * Quit after one exception * Fix type * Remove pending exception * Fix test --------- Co-authored-by: Connor Lewis <[email protected]> Co-authored-by: Patrick Arminio <[email protected]>
- Loading branch information
1 parent
861cc0d
commit 63dfc89
Showing
6 changed files
with
404 additions
and
182 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Release type: minor | ||
|
||
Starting with this release, any error raised from within schema | ||
extensions will abort the operation and is returned to the client. | ||
|
||
This corresponds to the way we already handle field extension errors | ||
and resolver errors. | ||
|
||
This is particular useful for schema extensions performing checks early | ||
in the request lifecycle, for example: | ||
|
||
```python | ||
class MaxQueryLengthExtension(SchemaExtension): | ||
MAX_QUERY_LENGTH = 8192 | ||
|
||
async def on_operation(self): | ||
if len(self.execution_context.query) > self.MAX_QUERY_LENGTH: | ||
raise StrawberryGraphQLError(message="Query too large") | ||
yield | ||
``` |
This file contains 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
Oops, something went wrong.