Skip to content

Commit

Permalink
Modify README to include Sanic example
Browse files Browse the repository at this point in the history
  • Loading branch information
hballard committed Jan 11, 2018
1 parent ab015f4 commit b1f39e7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Websocket server for GraphQL subscriptions.
Currently supports:
* [aiohttp](https://github.com/graphql-python/graphql-ws#aiohttp)
* [Gevent](https://github.com/graphql-python/graphql-ws#gevent)
* Sanic (uses [websockets](https://github.com/aaugustin/websockets/) library)

# Installation instructions

Expand Down Expand Up @@ -40,6 +41,27 @@ app.router.add_get('/subscriptions', subscriptions)
web.run_app(app, port=8000)
```

### Sanic

Works with any framework that uses the websockets library for
it's websocket implementation. For this example, plug in
your Sanic server.

```python
from graphql_ws.websockets_lib import WsLibSubscriptionServer


subscription_server = WsLibSubscriptionServer(schema)

@app.websocket('/subscriptions', subprotocols=['graphql-ws'])
async def subscriptions(request, ws):
await subscription_server.handle(ws)
return ws


app.run(host="0.0.0.0", port=8000)
```

And then, plug into a subscribable schema:

```python
Expand Down

0 comments on commit b1f39e7

Please sign in to comment.