Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8.16, 3.9.16, 3.10.11]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
Expand All @@ -55,11 +55,11 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.8.16, 3.9.16, 3.10.11]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
Expand Down
103 changes: 103 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (C) DATADVANCE, 2010-2023
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// VS Code configuration.
// https://code.visualstudio.com/docs/getstarted/settings

{
"cSpell.enabled": true,
"cSpell.allowCompoundWords": true,
"cSpell.words": [
"addfinalizer",
"aget",
"aiohttp",
"asdict",
"asgi",
"asgiref",
"asyncio",
"blazingly",
"choco",
"dedent",
"deserialization",
"edouardtheron",
"envlist",
"GQLWS",
"graphiql",
"graphql",
"inmemory",
"ipython",
"iscoroutinefunction",
"isfunction",
"isort",
"itertools",
"kwds",
"mutex",
"mymutation",
"mypy",
"myquery",
"mysubscription",
"nodeid",
"packb",
"posargs",
"prokhorov",
"pydocstyle",
"pyenchant",
"pyenv",
"pylint",
"pylintrc",
"pyproject",
"pytest",
"pyutils",
"rabbitmq",
"rcfile",
"repos",
"sessionid",
"skipif",
"testenv",
"Tomáš",
"unpackb",
"unsubscriptable",
"unsubscription",
"venv",
"virtualenv",
"wakeup",
"xdist",
"xenial",
"xfail",
"zen"
],
"editor.rulers": [72, 88],
"editor.tabSize": 4,
"git.ignoreLimitWarning": true,
"isort.args": ["--virtual-env", "${workspaceFolder}/.venv"],
"python.linting.banditEnabled": false,
"python.linting.mypyEnabled": true,
"python.linting.pydocstyleEnabled": false,
"python.linting.pylintEnabled": true,
"python.linting.pylintUseMinimalCheckers": false,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestArgs": ["-n8"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.pythonPath": ".venv/bin/python3",
"files.insertFinalNewline": true
}
33 changes: 31 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,42 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Changelog

## [Unreleased]

- Rebased with upstream `datadvance/DjangoChannelsGraphqlWs` (commit `1ade107`).
- Updated GitHub Actions CI: Python matrix bumped to 3.10 / 3.11 / 3.12;
`actions/checkout` and `actions/setup-python` upgraded from v2 to v4;
macOS runner added to test matrix.
- Fixed Python 3.10+ asyncio incompatibilities (event loop handling,
`asyncio.wait` coroutine usage).
- Fixed vulnerable `aiohttp` and `django` versions in `poetry.lock`.
- Post-rebase linting/formatting fixes (mypy, pylint, black 24.4.2).

## [1.0.0rc9] - 2024-04-11

- Package renamed to `baseapp-django-channels-graphql-ws` for PyPI distribution.
- Python requirement bumped to `^3.10.0`.
- Added Django 5 support: `Django = "^4 || ^5"`.

## [1.0.0rc8] - 2024-07-18

- Merged upstream changes from datadvance/DjangoChannelsGraphqlWs.
- Dependency upgrades and build fixes.
- Removed deprecated Pydocstyle.
- Made Poetry use active Python for compatibility with Pyenv.

## [1.0.0rc7] - 2023-08-17

- Supported the most recent WebSocket sub-protocol
`graphql-transport-ws` used by Apollo. See the specification:
https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md.


## [1.0.0rc6] - 2023-05-10

- GraphQL parsing and message serialization now perform concurrently
by `sync_to_async(...,thread_sensitive=False)`.


## [1.0.0rc5] - 2023-05-05

WARNING: Release contains backward incompatible changes!
Expand All @@ -38,7 +68,6 @@ WARNING: Release contains backward incompatible changes!
`SKIP` object which is no longer the case..
- Python 3.8 compatibility brought back. Tests pass OK.


## [1.0.0rc4] - 2023-05-03

- `GraphqlWsConsumer.warn_resolver_timeout` removed to avoid mess with
Expand Down
52 changes: 25 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ class MyGraphqlWsConsumer(channels_graphql_ws.GraphqlWsConsumer):
"""Channels WebSocket consumer which provides GraphQL API."""
schema = graphql_schema

# Uncomment to send keepalive message every 42 seconds.
# send_keepalive_every = 42
# Uncomment to send ping message every 42 seconds.
# send_ping_every = 42

# Uncomment to process requests sequentially (useful for tests).
# strict_ordering = True
Expand Down Expand Up @@ -261,25 +261,18 @@ You can start with the following GraphQL requests:
# Check there are no messages.
query read { history(chatroom: "kittens") { chatroom text sender }}

# Send a message as Anonymous.
# Send a message from your session.
mutation send { sendChatMessage(chatroom: "kittens", text: "Hi all!"){ ok }}

# Check there is a message from `Anonymous`.
# Check there is a message.
query read { history(chatroom: "kittens") { text sender } }

# Login as `user`.
mutation send { login(username: "user", password: "pass") { ok } }

# Send a message as a `user`.
mutation send { sendChatMessage(chatroom: "kittens", text: "It is me!"){ ok }}

# Check there is a message from both `Anonymous` and from `user`.
query read { history(chatroom: "kittens") { text sender } }

# Subscribe, do this from a separate browser tab, it waits for events.
# Open another browser or a new incognito window (to have another
# session cookie) subscribe to make it wait for events.
subscription s { onNewChatMessage(chatroom: "kittens") { text sender }}

# Send something again to check subscription triggers.
# Send another message from the original window and see how subscription
# triggers in the other one.
mutation send { sendChatMessage(chatroom: "kittens", text: "Something ;-)!"){ ok }}
```

Expand Down Expand Up @@ -310,12 +303,19 @@ recommended to have a look the documentation of these great projects:
- [Graphene](http://graphene-python.org/)

The implemented WebSocket-based protocol was taken from the library
[subscription-transport-ws](https://github.com/apollographql/subscriptions-transport-ws)
[graphql-ws](https://github.com/enisdenjo/graphql-ws)
which is used by the [Apollo GraphQL](https://github.com/apollographql).
Check the
[protocol description](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md)
[protocol description](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md)
for details.

NOTE: Prior to 1.0.0rc7 the library used another protocol:
[subscription-transport-ws](https://github.com/apollographql/subscriptions-transport-ws)
(see [the protocol description](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md)).
In fact [Apollo GraphQL](https://github.com/apollographql) has been
based on this protocol for years, but eventually has switched to a new
one, so we did this as well.


### Automatic Django model serialization

Expand Down Expand Up @@ -481,7 +481,7 @@ tracker.

To solve this problem, there is the `GraphqlWsConsumer` setting
`confirm_subscriptions` which when set to `True` will make the consumer
issue an additional `data` message which confirms the subscription
issue an additional `next` message which confirms the subscription
activation. Please note, you have to modify the client's code to make it
consume this message, otherwise it will be mistakenly considered as the
first subscription notification.
Expand Down Expand Up @@ -577,18 +577,16 @@ _A reminder of how to setup an environment for the development._
leave the project's directory. Inside the directory `pyenv which
python` should show you a python installed in pyenv, outside the dir
it should be the system python.
3. Install Poetry to the system Python.
4. Install Poetry (https://python-poetry.org/docs/#installation).
```shell
$ curl -sSL https://install.python-poetry.org | python3 -
$ pipx install poetry
```
It is important to install Poetry into the system Python, NOT in your
virtual environment. For details see Poetry docs: https://python-poetry.org/docs/#installation
4. Create local virtualenv in `.venv`, install all project dependencies
5. Create local virtualenv in `.venv`, install all project dependencies
(from `pyproject.toml`) except the project itself.
```shell
$ poetry install --no-root
```
5. Activate virtualenv
6. Activate virtualenv
There are options:
- With Poetry:
```shell
Expand All @@ -601,7 +599,7 @@ _A reminder of how to setup an environment for the development._
- With VS Code: Choose `.venv` with "Python: Select interpreter" and
reopen the terminal.

6. Upgrade Pip:
7. Upgrade Pip:
```shell
$ pip install --upgrade pip
```
Expand Down Expand Up @@ -632,8 +630,8 @@ the `Subscription`.
To better dive in it is useful to understand in general terms how
regular request are handled. When server receives JSON from the client,
the `GraphqlWsConsumer.receive_json` method is called by Channels
routines. Then the request passes to the `_on_gql_start` method which
handles GraphQL message "START". Most magic happens there.
routines. Then the request passes to the `_on_gql_subscribe` method
which handles GraphQL message "SUBSCRIBE". Most magic happens there.


### Running tests
Expand Down
Loading