From 6c26537ef43fe55be86dd51ac02ba6e464c81d2f Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 09:13:24 +0200 Subject: [PATCH 01/16] Fix channels import --- graphql_ws/django_channels.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/graphql_ws/django_channels.py b/graphql_ws/django_channels.py index ddba58d..7d2851f 100644 --- a/graphql_ws/django_channels.py +++ b/graphql_ws/django_channels.py @@ -1,6 +1,10 @@ import json -from channels.generic.websockets import JsonWebsocketConsumer +try: + # Channels version > 1 renamed the websockets module to websocket. + from channels.generic.websockets import JsonWebsocketConsumer +except ImportError: + from channels.generic.websocket import JsonWebsocketConsumer from graphene_django.settings import graphene_settings from .base import BaseConnectionContext From a360cf689b92edccf15f323136234a92ffbac16b Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 09:24:41 +0200 Subject: [PATCH 02/16] Bring changes from #74 --- graphql_ws/django/routing.py | 10 +++++++++- setup.cfg | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/graphql_ws/django/routing.py b/graphql_ws/django/routing.py index 15a1356..9a7030d 100644 --- a/graphql_ws/django/routing.py +++ b/graphql_ws/django/routing.py @@ -1,5 +1,7 @@ +from channels import __version__ as channels_version from channels.routing import ProtocolTypeRouter, URLRouter from channels.sessions import SessionMiddlewareStack +from django.utils.version import get_version_tuple from django.apps import apps from django.urls import path from .consumers import GraphQLSubscriptionConsumer @@ -10,7 +12,13 @@ AuthMiddlewareStack = None -websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer)] +channels_version_tuple = get_version_tuple(channels_version) + + +if channels_version_tuple > (3, 0 , 0): + websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer.as_asgi())] +else: + websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer)] application = ProtocolTypeRouter({"websocket": URLRouter(websocket_urlpatterns)}) diff --git a/setup.cfg b/setup.cfg index 3d07a80..29555e9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,6 +57,8 @@ test = channels==1.*; python_version<"3" django==2.*; python_version>="3" channels==2.*; python_version>="3" + django==3.*; python_version>="3" + channels==3.*; python_version>="3" aiohttp; python_version>="3.5" [bdist_wheel] From e651c9542bb4caf2c743a813caadcbf62391134f Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:02:14 +0200 Subject: [PATCH 03/16] Add github actions --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..60e2269 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: [main] + tags: + - v[0-9]+.[0-9]+.[0-9]+ + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + matrix: + python-version: ['2.7', '3.6', '3.7', '3.8', '3.9'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Dependencies + run: | + pip install -U tox-travis + - name: Run Tests + run: tox From 0c0abd13f8e08ec06fe827b7f0b7c3c893f45bb2 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:03:07 +0200 Subject: [PATCH 04/16] Support both master and main branch --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60e2269..50809c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,11 @@ name: CI on: push: - branches: [main] + branches: [main, master] tags: - v[0-9]+.[0-9]+.[0-9]+ pull_request: - branches: [main] + branches: [main, master] jobs: test: From 3ee849c7bddc3722e65735cc90f9ea794e3e5dc5 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:04:05 +0200 Subject: [PATCH 05/16] WIP, force trigger github action --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50809c3..e3d0e40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,12 @@ name: CI -on: - push: - branches: [main, master] - tags: - - v[0-9]+.[0-9]+.[0-9]+ - pull_request: - branches: [main, master] +on: push + # push: + # branches: [main, master] + # tags: + # - v[0-9]+.[0-9]+.[0-9]+ + # pull_request: + # branches: [main, master] jobs: test: From 3f3ccca45f359c28d6ea4cb918c4884a44b70904 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:06:56 +0200 Subject: [PATCH 06/16] Revert "WIP, force trigger github action" This reverts commit 3ee849c7bddc3722e65735cc90f9ea794e3e5dc5. --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3d0e40..50809c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,12 @@ name: CI -on: push - # push: - # branches: [main, master] - # tags: - # - v[0-9]+.[0-9]+.[0-9]+ - # pull_request: - # branches: [main, master] +on: + push: + branches: [main, master] + tags: + - v[0-9]+.[0-9]+.[0-9]+ + pull_request: + branches: [main, master] jobs: test: From 02ca5a64c232e2e82d7d2449e707bafcbb1ac7b3 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:09:13 +0200 Subject: [PATCH 07/16] Debug github actions not running --- .github/workflows/github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..02fdddc --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v2 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + From 0501fa9221864740a1f06866a37c03b930212742 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:10:47 +0200 Subject: [PATCH 08/16] Revert "Debug github actions not running" This reverts commit 02ca5a64c232e2e82d7d2449e707bafcbb1ac7b3. --- .github/workflows/github-actions-demo.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml deleted file mode 100644 index 02fdddc..0000000 --- a/.github/workflows/github-actions-demo.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: GitHub Actions Demo -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v2 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." - From 94694e8b8d9aae52cf4da5eb7ef892285d58da17 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:15:35 +0200 Subject: [PATCH 09/16] Reformat and add a script to the makefile --- Makefile | 5 ++++- graphql_ws/base.py | 2 +- graphql_ws/django/consumers.py | 1 - graphql_ws/django/routing.py | 6 ++++-- tests/test_base.py | 4 ++-- tests/test_base_async.py | 6 +++--- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 5c7501a..340999a 100644 --- a/Makefile +++ b/Makefile @@ -50,9 +50,12 @@ clean-test: ## remove test and coverage artifacts lint: ## check style with flake8 flake8 graphql_ws tests +format: + black ./graphql_ws ./tests + test: ## run tests quickly with the default Python py.test - + test-all: ## run tests on every Python version with tox tox diff --git a/graphql_ws/base.py b/graphql_ws/base.py index 31ad657..216d4f6 100644 --- a/graphql_ws/base.py +++ b/graphql_ws/base.py @@ -41,7 +41,7 @@ def remove_operation(self, op_id): def unsubscribe(self, op_id): async_iterator = self.remove_operation(op_id) - if hasattr(async_iterator, 'dispose'): + if hasattr(async_iterator, "dispose"): async_iterator.dispose() return async_iterator diff --git a/graphql_ws/django/consumers.py b/graphql_ws/django/consumers.py index b1c64d1..499febb 100644 --- a/graphql_ws/django/consumers.py +++ b/graphql_ws/django/consumers.py @@ -7,7 +7,6 @@ class GraphQLSubscriptionConsumer(AsyncJsonWebsocketConsumer): - async def connect(self): self.connection_context = None if WS_PROTOCOL in self.scope["subprotocols"]: diff --git a/graphql_ws/django/routing.py b/graphql_ws/django/routing.py index 9a7030d..395e0df 100644 --- a/graphql_ws/django/routing.py +++ b/graphql_ws/django/routing.py @@ -15,8 +15,10 @@ channels_version_tuple = get_version_tuple(channels_version) -if channels_version_tuple > (3, 0 , 0): - websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer.as_asgi())] +if channels_version_tuple > (3, 0, 0): + websocket_urlpatterns = [ + path("subscriptions", GraphQLSubscriptionConsumer.as_asgi()) + ] else: websocket_urlpatterns = [path("subscriptions", GraphQLSubscriptionConsumer)] diff --git a/tests/test_base.py b/tests/test_base.py index 1ce6300..f9f1e5b 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -91,7 +91,7 @@ def test_observer_data(): send_error=send_error, send_message=send_message, ) - observer.on_next('data') + observer.on_next("data") assert send_result.called assert not send_error.called @@ -107,6 +107,6 @@ def test_observer_exception(): send_error=send_error, send_message=send_message, ) - observer.on_next(TypeError('some bad message')) + observer.on_next(TypeError("some bad message")) assert send_error.called assert not send_result.called diff --git a/tests/test_base_async.py b/tests/test_base_async.py index d62eda5..7126c9e 100644 --- a/tests/test_base_async.py +++ b/tests/test_base_async.py @@ -83,18 +83,18 @@ async def test_resolver_with_promise(server): connection_context=None, op_id=1, execution_result=result ) assert server.send_message.called - assert result.data == {'test': [1, 2]} + assert result.data == {"test": [1, 2]} async def test_resolver_with_nested_promise(server): server.send_message = AsyncMock() result = mock.Mock() inner = promise.Promise(lambda resolve, reject: resolve(2)) - outer = promise.Promise(lambda resolve, reject: resolve({'in': inner})) + outer = promise.Promise(lambda resolve, reject: resolve({"in": inner})) result.data = {"test": [1, outer]} result.errors = None await server.send_execution_result( connection_context=None, op_id=1, execution_result=result ) assert server.send_message.called - assert result.data == {'test': [1, {'in': 2}]} + assert result.data == {"test": [1, {"in": 2}]} From a6eea7e5a74eea08961e66b6fa61a84f0dd5aa81 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:16:13 +0200 Subject: [PATCH 10/16] Add black to setup.cfg --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 29555e9..6376176 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,6 +41,7 @@ maintainer = PyYAML>=5.3,<6 dev = flake8>=3.7,<4 + black tox>=3,<4 Sphinx>=1.8,<2 test = From 94dbaaae7ac9b69c47e5bc0202b2a8c758fd3b04 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:18:22 +0200 Subject: [PATCH 11/16] Debug github actions failing --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50809c3..a472cf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,12 @@ name: CI -on: - push: - branches: [main, master] - tags: - - v[0-9]+.[0-9]+.[0-9]+ - pull_request: - branches: [main, master] +on: [push] + # push: + # branches: [main, master] + # tags: + # - v[0-9]+.[0-9]+.[0-9]+ + # pull_request: + # branches: [main, master] jobs: test: From 1d9b81cab8953cf276c7741a8a1ed862f74ad7b9 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:34:31 +0200 Subject: [PATCH 12/16] Set tox version in github actions --- .github/workflows/ci.yml | 17 +++++++++++++++-- setup.cfg | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a472cf4..fbe3c1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,19 @@ jobs: strategy: max-parallel: 5 matrix: + include: + - python-version: 2.7 + tox-version: "py27" + - python-version: 3.6 + tox-version: "py36" + - python-version: 3.7 + tox-version: "py37" + - python-version: 3.8 + tox-version: "py38" + - python-version: 3.9 + tox-version: "py39" + include: + - python-version: ['2.7', '3.6', '3.7', '3.8', '3.9'] steps: @@ -25,6 +38,6 @@ jobs: - name: Install Dependencies run: | - pip install -U tox-travis + pip install -U tox - name: Run Tests - run: tox + run: tox -e ${{ matrix.tox-version }} diff --git a/setup.cfg b/setup.cfg index 6376176..5bf8933 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,7 +51,6 @@ test = pytest-asyncio; python_version>="3.4" graphene>=2.0,<3 gevent - graphene>=2.0 graphene_django mock; python_version<"3" django==1.11.*; python_version<"3" From f85bb99223c897e82792d4614830d50545dbb1dc Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:35:00 +0200 Subject: [PATCH 13/16] Remove syntax error --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbe3c1f..c645945 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,6 @@ jobs: tox-version: "py38" - python-version: 3.9 tox-version: "py39" - include: - - python-version: ['2.7', '3.6', '3.7', '3.8', '3.9'] steps: From 43d447ff0bf33883b829743985d1d5dd0e470128 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:35:22 +0200 Subject: [PATCH 14/16] Remove syntax error... --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c645945..0ed602c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,6 @@ jobs: tox-version: "py38" - python-version: 3.9 tox-version: "py39" - python-version: ['2.7', '3.6', '3.7', '3.8', '3.9'] steps: - uses: actions/checkout@v2 From a36b30a96c3381143669646bced6fbdab8a49de2 Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:40:02 +0200 Subject: [PATCH 15/16] Use channels 3 and django 3 if available --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 5bf8933..3d24cca 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,8 +55,6 @@ test = mock; python_version<"3" django==1.11.*; python_version<"3" channels==1.*; python_version<"3" - django==2.*; python_version>="3" - channels==2.*; python_version>="3" django==3.*; python_version>="3" channels==3.*; python_version>="3" aiohttp; python_version>="3.5" From 0ad2b87d98c648805e44419057127cc7363609fb Mon Sep 17 00:00:00 2001 From: Fabien Le Frapper Date: Fri, 20 Aug 2021 11:41:06 +0200 Subject: [PATCH 16/16] Better target on which event trigger the github actions --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ed602c..4734531 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,12 @@ name: CI -on: [push] - # push: - # branches: [main, master] - # tags: - # - v[0-9]+.[0-9]+.[0-9]+ - # pull_request: - # branches: [main, master] +on: + push: + branches: [main, master] + tags: + - v[0-9]+.[0-9]+.[0-9]+ + pull_request: + branches: [main, master] jobs: test: