Skip to content

Commit f393228

Browse files
committed
Drop channels and custom subscriptions support
1 parent 4e4d063 commit f393228

File tree

15 files changed

+25
-360
lines changed

15 files changed

+25
-360
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,3 @@ jobs:
6868
cd tests
6969
python manage.py migrate
7070
python manage.py test
71-
72-
test_channels:
73-
runs-on: ubuntu-latest
74-
steps:
75-
- uses: actions/checkout@v3
76-
- name: Set up Python ${{ matrix.python-version }}
77-
uses: actions/setup-python@v4
78-
with:
79-
python-version: 3.8
80-
cache: 'pip'
81-
cache-dependency-path: |
82-
tests/requirements-channels.txt
83-
84-
- name: Install Dependencies
85-
run: |
86-
cd tests
87-
python -m pip install --upgrade pip
88-
python -m pip install -r requirements-channels.txt
89-
90-
- name: Run Tests
91-
run: |
92-
cd tests
93-
python manage.py migrate
94-
python manage.py test

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ COPY ./setup.py ./code/setup.py
2020

2121
# copy example site requires file
2222
COPY ./tests/requirements.txt /code/tests/requirements.txt
23-
COPY ./tests/requirements-channels.txt /code/tests/requirements-channels.txt
2423

2524
WORKDIR /code/tests
2625

2726
RUN pip install --upgrade pip
2827
# Install any needed packages specified in requirements.txt
29-
RUN pip install -r ./requirements-channels.txt
28+
RUN pip install -r ./requirements.txt
3029
RUN pip install gunicorn
3130

3231
# Copy the current directory contents into the container at /code/

README.md

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ A library to build GraphQL endpoints easily so you can grapple your Wagtail data
1919

2020
## About The Project
2121

22-
![GraphQL Preview Demo](docs/demo.gif)
23-
2422
There is a range of GraphQL packages for Python and specifically Django.
2523
However, getting these packages to work out of the box with an existing infrastructure
2624
without errors isn't as easy to come by.
@@ -35,28 +33,24 @@ to your model and away you go (although if you want to go deeper you can!).
3533

3634
- Easily create GraphQL types by adding a small annotation in your models.
3735
- Supports traditional Wagtail models:
38-
- Pages (including Streamfield & Orderables)
36+
- Pages (including StreamField & Orderables)
3937
- Snippets
4038
- Images
4139
- Documents
42-
- Media
40+
- Media (via [wagtailmedia](https://pypi.org/project/wagtailmedia/))
4341
- Settings
4442
- Redirects
4543
- Search (on all models)
4644
- Custom Image & Document model support
4745
- Pagination support
4846
- Middleware support
49-
- Advanced headless preview functionality built using GraphQL Subscriptions to enable Page previews on any device!
5047

5148
### Built With
5249

5350
This library is an abstraction upon and relies heavily on Graphene & Graphene Django.
54-
We also use Django Channels and the Potrace image library.
5551

5652
- [Graphene](https://github.com/graphql-python/graphene)
5753
- [Graphene Django](https://github.com/graphql-python/graphene)
58-
- [Potrace](https://github.com/skyrpex/potrace)
59-
- [Django Channels](https://github.com/django/channels) when installed with `wagtail_grapple[channels]`
6054

6155
## Getting Started
6256

@@ -65,7 +59,7 @@ Getting Grapple installed is designed to be as simple as possible!
6559
### Prerequisites
6660

6761
```
68-
Python>=3.8,<3.12
62+
Python >= 3.8
6963
Wagtail >= 4.1
7064
```
7165

@@ -88,19 +82,6 @@ INSTALLED_APPS = [
8882
]
8983
```
9084

91-
For GraphQL Subscriptions with Django Channels, run `pip install wagtail_grapple[channels]` and add
92-
`channels` to installed apps:
93-
94-
```python
95-
INSTALLED_APPS = [
96-
# ...
97-
"grapple",
98-
"graphene_django",
99-
"channels",
100-
# ...
101-
]
102-
```
103-
10485
Add the following to the bottom of the same settings file, where each key is the app you want to this library to scan and the value is the prefix you want to give to GraphQL types (you can usually leave this blank):
10586

10687
```python
@@ -114,6 +95,7 @@ GRAPPLE = {
11495
Add the GraphQL URLs to your `urls.py`:
11596

11697
```python
98+
from django.urls import include, path
11799
from grapple import urls as grapple_urls
118100

119101
# ...

docs/general-usage/hooks.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ Grapple provides a ``register_schema_mutation`` hook that is called when it crea
9090
Subscription
9191
^^^^^^^^^^^^
9292

93-
Note: subscriptions are only enabled when Grapple is installed with Django Channels: ``pip install wagtail_grapple[channels]``.
94-
Grapple provides a ``register_schema_subscription`` hook that is called when it creates the schema. You can use it to add your custom ``Subscription`` mixins
93+
Note: previously subscriptions were only enabled when Grapple was installed with Django Channels. We no longer provide
94+
out of the box support for subscriptions due to incompatibilities in the various dependencies.
95+
The ``register_schema_subscription`` hook is still provided. It is called when Grapple creates the schema.
96+
You can use it to add your custom ``Subscription`` mixins and functionality.
9597

9698
.. code-block:: python
9799
import asyncio

docs/general-usage/preview.rst

Lines changed: 2 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -6,114 +6,5 @@ Grapple also provides support for headless previews using the `Wagtail Headless
66
This means you can pass a unique 'preview token' to the GraphQL endpoint and preview a page as you update
77
it in the admin (in real-time!).
88

9-
Grapple's Headless Preview is built-on GraphQL Subscriptions which means
10-
that your client subscribes to the preview page and any changes in the Admin
11-
will be pushed to your client via WebSockets. This allows you to add preview
12-
support to any client whether that be a SPA or Native App.
13-
14-
Setup
15-
^^^^^
16-
17-
See :ref:`usage with subscriptions<usage-with-subscriptions>` first to make sure you installed Django Channels when you installed Grapple.
18-
Your installed apps in your settings should look like so:
19-
20-
.. code-block:: python
21-
22-
INSTALLED_APPS = [
23-
# ...
24-
"grapple",
25-
"graphene_django",
26-
"channels",
27-
"wagtail_headless_preview",
28-
# ...
29-
]
30-
31-
Now you need to run the migrations that come with Wagtail Headless Preview.
32-
33-
::
34-
35-
$ python manage.py migrate
36-
37-
38-
39-
You also want to add to your settings the URL you want to redirect to when the
40-
user clicks the 'Preview' button:
41-
42-
.. code-block:: python
43-
44-
HEADLESS_PREVIEW_CLIENT_URLS = {
45-
"default": "http://localhost:8001/preview",
46-
}
47-
48-
HEADLESS_PREVIEW_LIVE = True
49-
50-
Two HTTP params are also passed to this url:
51-
- ``content_type``: The content type string of the Model you're viewing.
52-
- ``token``: The preview token you need to retrieve the preview data.
53-
54-
*Attention*: When the user clicks the "Preview" or "View Draft" button in the Wagtail admin the preview opens in a new tab. The URL in the preview tab will not reveal the actual preview URL set in the setting. It will rather show the admin URL of the page with an additional URL element ``/preview`` or ``/view_draft`` (e.g. ``http://localhost:8000/admin/pages/5/edit/preview/``).
55-
56-
57-
Your next step is to subclass any Page models you want headless preview on with
58-
``wagtail_headless_preview.models.HeadlessPreviewMixin`` to override the original Wagtail preview methods:
59-
60-
.. code-block:: python
61-
62-
from wagtail_headless_preview.models import HeadlessPreviewMixin
63-
64-
65-
class BlogPage(HeadlessPreviewMixin, Page):
66-
author = models.CharField(max_length=255)
67-
date = models.DateField("Post date")
68-
advert = models.ForeignKey(
69-
"home.Advert",
70-
null=True,
71-
blank=True,
72-
on_delete=models.SET_NULL,
73-
related_name="+",
74-
)
75-
76-
77-
And you are done!
78-
79-
80-
How to use
81-
^^^^^^^^^^
82-
83-
Now when you click the 'Preview' button in Wagtail a page will open with the content of
84-
your defined `HEADLESS_PREVIEW_CLIENT_URLS`. You can either load the preview token through
85-
the HTTP params or through the ``used-token`` cookie which has been set in
86-
both the Admin and the redirected page.
87-
88-
Once you've pushed the 'Preview' button, Any data input into the Admin form
89-
will be pushed to your subscribed client. Pushing the button again will start
90-
a new session with a new token.
91-
92-
To access the preview data you can use one of the three queries (the 'subscription'
93-
declaration is optional if you want to do a one time query):
94-
95-
::
96-
97-
subscription {
98-
page(contentType: "home.blogpage", token: "id=4:1hg5FZ:bPmOihaRCLGbo4mzZagvrJAqNWM") {
99-
title
100-
}
101-
}
102-
103-
104-
::
105-
106-
subscription {
107-
page(slug: "example-blog-page", token: "id=4:1hg5FZ:bPmOihaRCLGbo4mzZagvrJAqNWM") {
108-
title
109-
}
110-
}
111-
112-
113-
::
114-
115-
subscription {
116-
page(id: 1, token: "id=4:1hg5FZ:bPmOihaRCLGbo4mzZagvrJAqNWM") {
117-
title
118-
}
119-
}
9+
See the `Wagtail Headless Preview<https://github.com/torchbox/wagtail-headless-preview>`_ documentation for setup
10+
instructions.

docs/getting-started/installation.rst

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,3 @@ By default, Grapple uses :doc:`these settings <../general-usage/settings>`.
5858

5959

6060
*Your GraphQL endpoint is available at http://localhost:8000/graphql/*
61-
62-
.. _usage-with-subscriptions:
63-
Usage with subscriptions
64-
========================
65-
66-
To enable GraphQL Subscriptions, you need to install Grapple with Django Channels.
67-
Run ``pip install wagtail_grapple[channels]`` and add ``channels`` to installed apps:
68-
69-
.. code-block:: python
70-
71-
INSTALLED_APPS = [
72-
# ...
73-
"grapple",
74-
"graphene_django",
75-
"channels",
76-
# ...
77-
]
78-
79-
Add the following Django Channels configuration to your settings.
80-
81-
.. code-block:: python
82-
83-
ASGI_APPLICATION = "graphql_ws.django.routing.application"

grapple/schema.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# to be a nice way to disable this validator so we monkey-patch it instead.
1313

1414

15-
# We can't simply override specified_rules because it's a tuple and immutable. Instead we are
16-
# monkey patching the NoUnusedFragmentRule.leave_document so it doesn't do any validation.
15+
# We can't simply override specified_rules because it's a tuple and immutable. Instead, we are
16+
# monkey patching the NoUnusedFragmentRule.leave_document, so it doesn't do any validation.
1717
NoUnusedFragmentsRule.leave_document = lambda self, *_args: None
1818

1919

@@ -23,8 +23,6 @@ def create_schema():
2323
It inherits its queries from each of the specific type mixins.
2424
"""
2525

26-
from .settings import has_channels
27-
2826
query_mixins = []
2927
for fn in hooks.get_hooks("register_schema_query"):
3028
fn(query_mixins)
@@ -40,34 +38,28 @@ class Query(*query_mixins):
4038
for fn in hooks.get_hooks("register_schema_mutation"):
4139
fn(mutation_mixins)
4240

43-
# ensure graphene.ObjectType is always present
44-
if graphene.ObjectType not in mutation_mixins:
45-
mutation_mixins.append(graphene.ObjectType)
46-
47-
if len(mutation_mixins) > 1:
41+
if len(mutation_mixins) > 0:
42+
# ensure graphene.ObjectType is always present
43+
if graphene.ObjectType not in mutation_mixins:
44+
mutation_mixins.append(graphene.ObjectType)
4845

4946
class Mutation(*mutation_mixins):
5047
pass
5148

5249
else:
5350
Mutation = None
5451

55-
if has_channels:
56-
subscription_mixins = []
57-
for fn in hooks.get_hooks("register_schema_subscription"):
58-
fn(subscription_mixins)
52+
subscription_mixins = []
53+
for fn in hooks.get_hooks("register_schema_subscription"):
54+
fn(subscription_mixins)
5955

56+
if len(subscription_mixins) > 0:
6057
# ensure graphene.ObjectType is always present
6158
if graphene.ObjectType not in subscription_mixins:
6259
subscription_mixins.append(graphene.ObjectType)
6360

64-
if len(subscription_mixins) > 1:
65-
66-
class Subscription(*subscription_mixins):
67-
pass
68-
69-
else:
70-
Subscription = None
61+
class Subscription(*subscription_mixins):
62+
pass
7163

7264
else:
7365
Subscription = None

grapple/settings.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616

1717
logger = logging.getLogger("grapple")
1818

19-
try:
20-
import channels # noqa: F401
21-
22-
has_channels = True
23-
except ImportError:
24-
has_channels = False
25-
2619

2720
DEFAULTS = {
2821
"APPS": [],

0 commit comments

Comments
 (0)