-
-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support subscriptions extensions (#3554)
* Support subscriptions extensions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add RELEASE.md * mypy fixes. * remove positional only / (py3.7) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reverts * intial subscription test pass * wip. pass manager to graphql core * wip: migrate to new graphql core * don't use supports resolve * revert * revert unneeded changes * restore tests; inject execution_context on operation * don't use class; depecate * wip: ensure execution context is distinct. * wip: first inital successful run after refactor * wip: more tests pass * better release.md * all previous extensions tests pass * update release.md * improve tests readability * test_subscription_success_many_fields pass * test_subscription_first_yields_error * test_extensino_results_are_cleared_between_yields * test_extensino_results_are_cleared_between_yields * fix extensions tests * ai lints * refactor; fix more tests * ensure `on_execute` and `get_result` hooks are deterministically ordered. * handle `on_execute` exceptions. * move missing query error before parsing phase. * wip: remove unneeded exception handler for `sync_execute` * fix more tests * refactor: separate subscription tests from normal tests. * fix websocket tests * fix mypy * move to graphql-core origin@main * nit * fix: handle not awaitable result of `original_subscribe` * add th `assert_next` * nits * nit * nit * nits * reorder execute.py * docs. * use `.aclose` * fix mypy issues. * fix unused `else` * move execution context injection upwards. * nit * add test for when extensios not return anything. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * wip: remove implements_get_result check * working on tests * schema tests pass * lints * fix more tests * wip: working on tests. * fix graphql-transport-ws * graphql-ws tests pass * tests were always running on 3.3 XD * pass middleware manager only in 3.3 * fix some mypy issues * fix more tests. * fix graphql-ws-transport protocol behaviour on (pre)execution errors * resolve optimization todos. * add `long_runnning` subscription benchmark; update release.md; improve coverage. * fix contextvar issue + few redundant changes. * feat: add lazy loading for images in test_subscriptions benchmark * typos in readme * fix tests. * recify reviews; nits & move `_implements_resolve` to `SchemaExtension` * refactor: update GraphQL version check logic in utils/__init__.py * rectify review comments * rectify @DoctorJohn review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * rectify @bellini666 comments * Improve protocol handling for subscriptions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Lint * Restore tests * Update wrong return type * Update doc * Temporarily skip on_execute, see #3613 * Update multipart tests * Fix bad merge * Fix type * remove unneeded async gen wrapper since we removed support for on_execute hook * Update release notes * Add tweet.md --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Patrick Arminio <patrick.arminio@gmail.com>
- Loading branch information
1 parent
fc25e04
commit 0dcf23d
Showing
32 changed files
with
1,268 additions
and
631 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,36 @@ | ||
Release type: minor | ||
|
||
This release adds support for schema-extensions in subscriptions. | ||
|
||
Here's a small example of how to use them (they work the same way as query and | ||
mutation extensions): | ||
|
||
```python | ||
import asyncio | ||
from typing import AsyncIterator | ||
|
||
import strawberry | ||
from strawberry.extensions.base_extension import SchemaExtension | ||
|
||
|
||
@strawberry.type | ||
class Subscription: | ||
@strawberry.subscription | ||
async def notifications(self, info: strawberry.Info) -> AsyncIterator[str]: | ||
for _ in range(3): | ||
yield "Hello" | ||
|
||
|
||
class MyExtension(SchemaExtension): | ||
async def on_operation(self): | ||
# This would run when the subscription starts | ||
print("Subscription started") | ||
yield | ||
# The subscription has ended | ||
print("Subscription ended") | ||
|
||
|
||
schema = strawberry.Schema( | ||
query=Query, subscription=Subscription, extensions=[MyExtension] | ||
) | ||
``` |
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,5 @@ | ||
🆕 Release $version is out! Thanks to $contributor for the PR 👏 | ||
|
||
This release adds supports for schema extensions to subscriptions! | ||
|
||
Get it here 👉 $release_url |
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
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,36 @@ | ||
--- | ||
title: 0.240.0 Breaking Changes | ||
slug: breaking-changes/0.240.0 | ||
--- | ||
|
||
# v0.240.0 updates `Schema.subscribe`'s signature | ||
|
||
In order to support schema extensions in subscriptions and errors that can be | ||
raised before the execution of the subscription, we had to update the signature | ||
of `Schema.subscribe`. | ||
|
||
Previously it was: | ||
|
||
```python | ||
async def subscribe( | ||
self, | ||
query: str, | ||
variable_values: Optional[Dict[str, Any]] = None, | ||
context_value: Optional[Any] = None, | ||
root_value: Optional[Any] = None, | ||
operation_name: Optional[str] = None, | ||
) -> Union[AsyncIterator[GraphQLExecutionResult], GraphQLExecutionResult]: | ||
``` | ||
|
||
Now it is: | ||
|
||
```python | ||
async def subscribe( | ||
self, | ||
query: Optional[str], | ||
variable_values: Optional[Dict[str, Any]] = None, | ||
context_value: Optional[Any] = None, | ||
root_value: Optional[Any] = None, | ||
operation_name: Optional[str] = None, | ||
) -> Union[AsyncGenerator[ExecutionResult, None], PreExecutionError]: | ||
``` |
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
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
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
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
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
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
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.