-
-
Notifications
You must be signed in to change notification settings - Fork 555
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
Refactor how we handle PreExecution errors #3787
base: main
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis pull request refactors how Sequence diagram for handling PreExecutionError in graphql_transport_wssequenceDiagram
participant Client
participant Server
participant Schema
participant Operation
Client->>Server: SubscribeMessage
Server->>Schema: schema.subscribe(query, variables, operation_name, context, root_value)
Schema->>Schema: _subscribe(...)
alt PreExecutionError
Schema-->>Server: PreExecutionError
Server->>Operation: send_initial_errors(errors)
Operation->>Client: Sends error message
else SubscriptionResult
Schema-->>Server: AsyncGenerator[ExecutionResult]
Server->>Operation: result_source
loop For each result in result_source
Operation->>Client: send_next(result)
end
Operation->>Client: send_operation_message({type: \"complete\"})
end
Sequence diagram for handling PreExecutionError in graphql_wssequenceDiagram
participant Client
participant Server
participant Schema
Client->>Server: Subscribe (query, variables, operation_name)
Server->>Schema: schema.subscribe(query, variables, operation_name, context, root_value)
Schema->>Schema: _subscribe(...)
alt PreExecutionError
Schema-->>Server: PreExecutionError
Server->>Server: send_message({type: \"error\", id: operation_id, payload: error})
Server->>Client: Sends error message
else SubscriptionResult
Schema-->>Server: AsyncGenerator[ExecutionResult]
Server->>Server: result_source
loop For each result in result_source
Server->>Server: send_data_message(result, operation_id)
Server->>Client: Sends data message
end
Server->>Server: send_message({type: \"complete\", id: operation_id})
Server->>Client: Sends complete message
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
4a2d8ab
to
2857dc1
Compare
for more information, see https://pre-commit.ci
Next step would be to change the PreExecution error to an exception |
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.
Hey @patrick91 - I've reviewed your changes - here's some feedback:
Overall Comments:
- It looks like you're handling
PreExecutionError
differently for subscriptions and other operations; is this intentional? - Consider adding a test case specifically for
PreExecutionError
in subscriptions to ensure the fix works as expected.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
else: | ||
async for result in first_res_or_agen: | ||
is_first_result = True |
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.
issue (complexity): Consider separating the processing of the first result from the rest of the asynchronous iterator to improve readability.
Consider separating the processing of the first result from the subsequent ones to eliminate the inline flag and nested condition. For example, you could immediately obtain the first value from the async iterator and then process the rest. This keeps the functionality identical while making the control flow easier to follow. For instance:
# Replace the current else clause with:
# For async generators:
first_result = None
aiter = result_source.__aiter__()
try:
first_result = await aiter.__anext__()
except StopAsyncIteration:
pass
if first_result is None:
pass # Optionally, handle the case of no results.
elif isinstance(first_result, PreExecutionError):
await operation.send_initial_errors(first_result.errors)
else:
await operation.send_next(first_result)
async for result in aiter:
await operation.send_next(result)
This refactoring removes the need for an is_first_result
flag and simplifies the logic while keeping all behavior intact.
Hi, thanks for contributing to Strawberry 🍓! We noticed that this PR is missing a So as soon as this PR is merged, a release will be made 🚀. Here's an example of Release type: patch
Description of the changes, ideally with some examples, if adding a new feature. Release type can be one of patch, minor or major. We use semver, so make sure to pick the appropriate type. If in doubt feel free to ask :) Here's the tweet text:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3787 +/- ##
==========================================
- Coverage 97.23% 95.24% -2.00%
==========================================
Files 503 499 -4
Lines 33529 32360 -1169
Branches 1716 1679 -37
==========================================
- Hits 32603 30820 -1783
- Misses 707 1275 +568
- Partials 219 265 +46 |
CodSpeed Performance ReportMerging #3787 will not alter performanceComparing Summary
|
Summary by Sourcery
Enhancements: