-
-
Notifications
You must be signed in to change notification settings - Fork 660
feat: add mask_pre_execution_errors option to MaskErrors
#4577
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
Open
alimony
wants to merge
3
commits into
strawberry-graphql:main
Choose a base branch
from
alimony:mask-pre-execution-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| release type: minor | ||
| social_messages: | ||
| x: >- | ||
| {project_name} {version} is out! This release adds a | ||
| `mask_pre_execution_errors` option to `MaskErrors`, so clients can still see | ||
| why their query is invalid. 🍓 https://strawberry.rocks/release/{version} | ||
| linkedin: >- | ||
| {project_name} {version} is out. This release adds a | ||
| `mask_pre_execution_errors` option to the `MaskErrors` extension, so syntax | ||
| and validation errors can reach clients while the errors your resolvers | ||
| raise stay masked. | ||
| --- | ||
|
|
||
| This release adds a `mask_pre_execution_errors` option to the `MaskErrors` extension. | ||
|
|
||
| `MaskErrors` masks every error. This includes the syntax errors of a document and the validation errors against the schema, so a client that sends an invalid query gets only the generic message. Set the new option to `False` to send these errors to the client. The errors that your resolvers raise stay masked: | ||
|
|
||
| ```python | ||
| import strawberry | ||
| from strawberry.extensions import MaskErrors | ||
|
|
||
|
|
||
| @strawberry.type | ||
| class Query: | ||
| @strawberry.field | ||
| def hello(self) -> str: | ||
| return "world" | ||
|
|
||
| @strawberry.field | ||
| def hidden_error(self) -> str: | ||
| raise KeyError("This error will not be visible") | ||
|
|
||
|
|
||
| schema = strawberry.Schema( | ||
| Query, | ||
| extensions=[ | ||
| lambda: MaskErrors(mask_pre_execution_errors=False), | ||
| ], | ||
| ) | ||
|
|
||
| # "Cannot query field 'helloo' on type 'Query'. Did you mean 'hello'?" | ||
| schema.execute_sync("{ helloo }") | ||
|
|
||
| # "Unexpected error." | ||
| schema.execute_sync("{ hiddenError }") | ||
| ``` | ||
|
|
||
| The default value is `True`, which keeps the current behaviour. Validation errors give the names of the fields, the arguments and the types of your schema. Thus disable the option only if the clients can know the shape of the schema. |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.