Skip to content

Commit

Permalink
Add basic Channels integration (#1407)
Browse files Browse the repository at this point in the history
* Update dependencies

Add Channels optional dependency and an Extra package for channels

* Add documentation for Channels integration

* Add implementation for basic Channels integration

Complete implementation for websockets, partial implementation for HTTP (multipart/form-data still pending)

* Add unit tests for Channels integration

These unit tests are mostly copied over from FastAPI, and certainly aren't comprehensive or covering all the Channels-specific cases. However, they provide a reasonably good level of coverage for actual protocol behaviour.

The HTTP consumer does not yet have any unit tests.

* Add channels as dev dependency

* Fix code for python 3.7

* Update docs formatting

* Add release notes

* Fix typo

* Initial fixes for GET request

* Fix http handler

* fix: Handle disconnect should also reap completed tasks

* test: Fix channels websockets tests

* chore: Fix typing issues

* refactor: Pass the original error message along instead of a custom one

* fix: Fix urlpattern to handle `^graphql` instead of `^graph`

* feat: Finish HttpConsumer and also implement a sync version, with full testing coverage

* refactor: Inherit all handlers from the same base and better organize everything

* feat: Add channels layer typing protocol

* feat: Add a high level api for layers communication

* docs: Document how to use the high level layers event listener

* fix: Import Protocol from typing_extensions

* fix: Fix a typing issue with override

* fix: Fix the pyright test that just broke today

* test: Cover channels integration 100%

* fix: Pass response already encoded so that graphiql result doesn't get json encoded

* fix: Fix should_render_graphiql checking

* refactor: Handle invalid operation generically

* docs: Fix a small typo on documentation

* feat: Check for layers integration and give a better error message in case it is not found

* docs: Add a missing comma in documentation example

* check channels docs.

* check channels docs - fix .md references from camelCase to no case.

* check channels docs - added gql queries

* add tests docs

* add tests docs - added note about pytest.

* Fix .md code block annotation

Co-authored-by: Patrick Arminio <patrick.arminio@gmail.com>

* fixed grammar more clear explanation, formatting

* fix 404

* refactor: Only allow dotted access to channels context

* feat: Properly type channel_listen method

* channels docs - fit

* update fork (#1)

* Bump ddtrace from 1.2.3 to 1.3.0 (#2050)

Bumps [ddtrace](https://github.com/DataDog/dd-trace-py) from 1.2.3 to 1.3.0.
- [Release notes](https://github.com/DataDog/dd-trace-py/releases)
- [Changelog](https://github.com/DataDog/dd-trace-py/blob/1.x/CHANGELOG.md)
- [Commits](DataDog/dd-trace-py@v1.2.3...v1.3.0)

---
updated-dependencies:
- dependency-name: ddtrace
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump types-setuptools from 63.2.1 to 63.2.2 (#2049)

Bumps [types-setuptools](https://github.com/python/typeshed) from 63.2.1 to 63.2.2.
- [Release notes](https://github.com/python/typeshed/releases)
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-setuptools
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add support for printing dictionaries when using custom scalars (#2048)

* Add support for printing dictionaries when using custom scalars

* Add support for nested dicts

* Add support for arguments

* Add test for bool and float

* Add test for id

* Test for list with values

* Add comment back

* Fix variable

* More tests

* More tests for lists

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add support for objects as default values

* Test more cases

* Ignore code paths

* Add one more test for floats

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Release 馃崜 0.122.0

* Remove autoreload test (#2053)

* Fix aiohttp query operation selection (#2055)

* Release 馃崜 0.122.1

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Patrick Arminio <patrick.arminio@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Botberry <bot@strawberry.rocks>
Co-authored-by: Jonathan Ehwald <github@ehwald.info>

* Update docs/integrations/django.md

Co-authored-by: Jonathan Ehwald <github@ehwald.info>

* refactor: Remove not needed connection init timeout task cancellation

* refactor: s/import pathlib/from pathlib import Path/

* refactor: Default groups to an empty tuple

* chore: Add back channels dev dependency

* test: Fix tests that broke after last change to channel_listen

* docs: Add an explanation to why GraphqlWSHandler implements a handle_invalid_message method

* Update strawberry/channels/handlers/http_handler.py

Co-authored-by: Hans Huber <69171298+hans-brilliant@users.noreply.github.com>

* test: Fix tests that broke after last change

* Add log and missing marker

* Update release notes

* Minor docs update

* Add tweet file

* Docs update

Co-authored-by: Patrick Arminio <patrick.arminio@gmail.com>
Co-authored-by: Thiago Bellini Ribeiro <thiago@bellini.dev>
Co-authored-by: Nir <88795475+nrbnlulu@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Botberry <bot@strawberry.rocks>
Co-authored-by: Jonathan Ehwald <github@ehwald.info>
Co-authored-by: Thiago Bellini Ribeiro <hackedbellini@gmail.com>
Co-authored-by: Hans Huber <69171298+hans-brilliant@users.noreply.github.com>
  • Loading branch information
10 people committed Aug 12, 2022
1 parent 091dd22 commit d4501ae
Show file tree
Hide file tree
Showing 27 changed files with 3,645 additions and 623 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release type: minor

This release adds an integration with Django Channels. The integration will
allow you to use GraphQL subscriptions via Django Channels.
5 changes: 5 additions & 0 deletions TWEET.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
馃啎 Release $version is out! This time with a new integration for Django channels. Feel free to test this out and let us know how it works!

Thanks to @Lucid_Dan, @_bellini666 and Nir (https://github.com/nrbnlulu) for working on this PR!

Get it here 馃憠 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- [AIOHTTP](./integrations/aiohttp.md)
- [ASGI](./integrations/asgi.md)
- [Django](./integrations/django.md)
- [Channels](./integrations/channels.md)
- [FastAPI](./integrations/fastapi.md)
- [Flask](./integrations/flask.md)
- [Sanic](./integrations/sanic.md)
Expand Down
26 changes: 26 additions & 0 deletions docs/general/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,32 @@ app = GraphQL(schema, subscription_protocols=[
])
```

##### Django + Channels

```python
import os

from django.core.asgi import get_asgi_application
from strawberry.channels import GraphQLProtocolTypeRouter

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
django_asgi_app = get_asgi_application()

# Import your Strawberry schema after creating the django ASGI application
# This ensures django.setup() has been called before any ORM models are imported
# for the schema.
from mysite.graphql import schema


application = GraphQLProtocolTypeRouter(
schema,
django_application=django_asgi_app,
)
```

Note: Check the [channels integraton](/docs/integrations/channels.md) page for more information
regarding the it.

### Single result operations

In addition to _streaming operations_ (i.e. subscriptions),
Expand Down

0 comments on commit d4501ae

Please sign in to comment.