Skip to content

Commit b1f39e7

Browse files
committed
Modify README to include Sanic example
1 parent ab015f4 commit b1f39e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Websocket server for GraphQL subscriptions.
55
Currently supports:
66
* [aiohttp](https://github.com/graphql-python/graphql-ws#aiohttp)
77
* [Gevent](https://github.com/graphql-python/graphql-ws#gevent)
8+
* Sanic (uses [websockets](https://github.com/aaugustin/websockets/) library)
89

910
# Installation instructions
1011

@@ -40,6 +41,27 @@ app.router.add_get('/subscriptions', subscriptions)
4041
web.run_app(app, port=8000)
4142
```
4243

44+
### Sanic
45+
46+
Works with any framework that uses the websockets library for
47+
it's websocket implementation. For this example, plug in
48+
your Sanic server.
49+
50+
```python
51+
from graphql_ws.websockets_lib import WsLibSubscriptionServer
52+
53+
54+
subscription_server = WsLibSubscriptionServer(schema)
55+
56+
@app.websocket('/subscriptions', subprotocols=['graphql-ws'])
57+
async def subscriptions(request, ws):
58+
await subscription_server.handle(ws)
59+
return ws
60+
61+
62+
app.run(host="0.0.0.0", port=8000)
63+
```
64+
4365
And then, plug into a subscribable schema:
4466

4567
```python

0 commit comments

Comments
 (0)