Skip to content

Commit 8565d1c

Browse files
authored
Merge pull request #45 from SmileyChris/master
Update setup configuration and create initial tests
2 parents d7850c5 + 923fc08 commit 8565d1c

17 files changed

+590
-366
lines changed

HISTORY.rst

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22
History
33
=======
44

5+
0.3.0 (2018-09-25)
6+
==================
7+
8+
- Django channels (v1) server (with example app).
9+
10+
- Websockets lib server (with example app).
11+
12+
- Observable aiter server.
13+
14+
15+
0.2.0 (2017-11-18)
16+
==================
17+
18+
- Add gevent subscription server.
19+
20+
- Add example flask gevent app.
21+
22+
523
0.1.0 (2017-10-15)
6-
------------------
24+
==================
725

8-
* First release on PyPI.
26+
- First release on PyPI.

MANIFEST.in

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ include CONTRIBUTING.rst
33
include HISTORY.rst
44
include LICENSE
55
include README.rst
6+
include tox.ini
67

7-
recursive-include tests *
8-
recursive-exclude * __pycache__
9-
recursive-exclude * *.py[co]
8+
graft tests
9+
global-exclude __pycache__
10+
global-exclude *.py[co]
1011

1112
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif

README.md

-205
This file was deleted.

README.rst

+102-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ GraphQL WS
33

44
Websocket server for GraphQL subscriptions.
55

6-
Currently supports: \*
7-
`aiohttp <https://github.com/graphql-python/graphql-ws#aiohttp>`__ \*
8-
`Gevent <https://github.com/graphql-python/graphql-ws#gevent>`__
6+
Currently supports:
7+
8+
* `aiohttp <https://github.com/graphql-python/graphql-ws#aiohttp>`__
9+
* `Gevent <https://github.com/graphql-python/graphql-ws#gevent>`__
10+
* Sanic (uses `websockets <https://github.com/aaugustin/websockets/>`__
11+
library)
912

1013
Installation instructions
1114
=========================
@@ -44,6 +47,29 @@ For setting up, just plug into your aiohttp server.
4447
4548
web.run_app(app, port=8000)
4649
50+
Sanic
51+
~~~~~
52+
53+
Works with any framework that uses the websockets library for it’s
54+
websocket implementation. For this example, plug in your Sanic server.
55+
56+
.. code:: python
57+
58+
from graphql_ws.websockets_lib import WsLibSubscriptionServer
59+
60+
61+
app = Sanic(__name__)
62+
63+
subscription_server = WsLibSubscriptionServer(schema)
64+
65+
@app.websocket('/subscriptions', subprotocols=['graphql-ws'])
66+
async def subscriptions(request, ws):
67+
await subscription_server.handle(ws)
68+
return ws
69+
70+
71+
app.run(host="0.0.0.0", port=8000)
72+
4773
And then, plug into a subscribable schema:
4874

4975
.. code:: python
@@ -110,4 +136,76 @@ And then, plug into a subscribable schema:
110136
schema = graphene.Schema(query=Query, subscription=Subscription)
111137
112138
You can see a full example here:
113-
https://github.com/graphql-python/graphql-ws/tree/master/examples/flask\_gevent
139+
https://github.com/graphql-python/graphql-ws/tree/master/examples/flask_gevent
140+
141+
Django Channels
142+
~~~~~~~~~~~~~~~
143+
144+
First ``pip install channels`` and it to your django apps
145+
146+
Then add the following to your settings.py
147+
148+
.. code:: python
149+
150+
CHANNELS_WS_PROTOCOLS = ["graphql-ws", ]
151+
CHANNEL_LAYERS = {
152+
"default": {
153+
"BACKEND": "asgiref.inmemory.ChannelLayer",
154+
"ROUTING": "django_subscriptions.urls.channel_routing",
155+
},
156+
157+
}
158+
159+
Setup your graphql schema
160+
161+
.. code:: python
162+
163+
import graphene
164+
from rx import Observable
165+
166+
167+
class Query(graphene.ObjectType):
168+
hello = graphene.String()
169+
170+
def resolve_hello(self, info, **kwargs):
171+
return 'world'
172+
173+
class Subscription(graphene.ObjectType):
174+
175+
count_seconds = graphene.Int(up_to=graphene.Int())
176+
177+
178+
def resolve_count_seconds(
179+
root,
180+
info,
181+
up_to=5
182+
):
183+
return Observable.interval(1000)\
184+
.map(lambda i: "{0}".format(i))\
185+
.take_while(lambda i: int(i) <= up_to)
186+
187+
188+
189+
schema = graphene.Schema(
190+
query=Query,
191+
subscription=Subscription
192+
)
193+
194+
Setup your schema in settings.py
195+
196+
.. code:: python
197+
198+
GRAPHENE = {
199+
'SCHEMA': 'path.to.schema'
200+
}
201+
202+
and finally add the channel routes
203+
204+
.. code:: python
205+
206+
from channels.routing import route_class
207+
from graphql_ws.django_channels import GraphQLSubscriptionConsumer
208+
209+
channel_routing = [
210+
route_class(GraphQLSubscriptionConsumer, path=r"^/subscriptions"),
211+
]

bin/convert_documentation

-3
This file was deleted.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db.sqlite3

graphql_ws/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
__version__ = '0.3.1'
88

99

10-
from .base import BaseConnectionContext, BaseSubscriptionServer
11-
12-
__all__ = ['BaseConnectionContext', 'BaseSubscriptionServer']
10+
from .base import BaseConnectionContext, BaseSubscriptionServer # noqa: F401

0 commit comments

Comments
 (0)