Skip to content

Commit 991bafe

Browse files
committed
Improved Readme
1 parent d651051 commit 991bafe

File tree

4 files changed

+129
-15
lines changed

4 files changed

+129
-15
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
Websocket server for GraphQL subscriptions.
44

5-
# Installation instructions
6-
7-
For having a demo with Python 3.6:
5+
Currently supports:
6+
* [aiohttp](https://github.com/graphql-python/graphql-ws#aiohttp)
7+
* [Gevent](https://github.com/graphql-python/graphql-ws#gevent)
88

9-
```shell
10-
git clone https://github.com/graphql-python/graphql-ws.git
11-
cd graphql-ws
9+
# Installation instructions
1210

13-
# Install the package
14-
python setup.py develop
15-
pip install -r requirements_dev.txt
11+
For instaling graphql-ws, just run this command in your shell
1612

17-
# Demo time!
18-
cd examples
19-
python aio.py
13+
```bash
14+
pip install graphql-ws
2015
```
2116

22-
## Setup
17+
## Examples
2318

2419
### aiohttp
2520

@@ -69,6 +64,7 @@ class Subscription(graphene.ObjectType):
6964
schema = graphene.Schema(query=Query, subscription=Subscription)
7065
```
7166

67+
You can see a full example here: https://github.com/graphql-python/graphql-ws/tree/master/examples/aiohttp
7268

7369
### Gevent
7470

@@ -106,3 +102,5 @@ class Subscription(graphene.ObjectType):
106102

107103
schema = graphene.Schema(query=Query, subscription=Subscription)
108104
```
105+
106+
You can see a full example here: https://github.com/graphql-python/graphql-ws/tree/master/examples/flask_gevent

README.rst

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
GraphQL WS
2+
==========
3+
4+
Websocket server for GraphQL subscriptions.
5+
6+
Currently supports: \*
7+
`aiohttp <https://github.com/graphql-python/graphql-ws#aiohttp>`__ \*
8+
`Gevent <https://github.com/graphql-python/graphql-ws#gevent>`__
9+
10+
Installation instructions
11+
=========================
12+
13+
For instaling graphql-ws, just run this command in your shell
14+
15+
.. code:: bash
16+
17+
pip install graphql-ws
18+
19+
Examples
20+
--------
21+
22+
aiohttp
23+
~~~~~~~
24+
25+
For setting up, just plug into your aiohttp server.
26+
27+
.. code:: python
28+
29+
from graphql_ws.aiohttp import AiohttpSubscriptionServer
30+
31+
32+
subscription_server = AiohttpSubscriptionServer(schema)
33+
34+
async def subscriptions(request):
35+
ws = web.WebSocketResponse(protocols=('graphql-ws',))
36+
await ws.prepare(request)
37+
38+
await subscription_server.handle(ws)
39+
return ws
40+
41+
42+
app = web.Application()
43+
app.router.add_get('/subscriptions', subscriptions)
44+
45+
web.run_app(app, port=8000)
46+
47+
And then, plug into a subscribable schema:
48+
49+
.. code:: python
50+
51+
import asyncio
52+
import graphene
53+
54+
55+
class Query(graphene.ObjectType):
56+
base = graphene.String()
57+
58+
59+
class Subscription(graphene.ObjectType):
60+
count_seconds = graphene.Float(up_to=graphene.Int())
61+
62+
async def resolve_count_seconds(root, info, up_to):
63+
for i in range(up_to):
64+
yield i
65+
await asyncio.sleep(1.)
66+
yield up_to
67+
68+
69+
schema = graphene.Schema(query=Query, subscription=Subscription)
70+
71+
You can see a full example here:
72+
https://github.com/graphql-python/graphql-ws/tree/master/examples/aiohttp
73+
74+
Gevent
75+
~~~~~~
76+
77+
For setting up, just plug into your Gevent server.
78+
79+
.. code:: python
80+
81+
subscription_server = GeventSubscriptionServer(schema)
82+
app.app_protocol = lambda environ_path_info: 'graphql-ws'
83+
84+
@sockets.route('/subscriptions')
85+
def echo_socket(ws):
86+
subscription_server.handle(ws)
87+
return []
88+
89+
And then, plug into a subscribable schema:
90+
91+
.. code:: python
92+
93+
import graphene
94+
from rx import Observable
95+
96+
97+
class Query(graphene.ObjectType):
98+
base = graphene.String()
99+
100+
101+
class Subscription(graphene.ObjectType):
102+
count_seconds = graphene.Float(up_to=graphene.Int())
103+
104+
async def resolve_count_seconds(root, info, up_to=5):
105+
return Observable.interval(1000)\
106+
.map(lambda i: "{0}".format(i))\
107+
.take_while(lambda i: int(i) <= up_to)
108+
109+
110+
schema = graphene.Schema(query=Query, subscription=Subscription)
111+
112+
You can see a full example here:
113+
https://github.com/graphql-python/graphql-ws/tree/master/examples/flask\_gevent

bin/convert_documentation

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
pandoc README.md --from markdown --to rst -s -o README.rst

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from setuptools import setup, find_packages
77

8-
# with open('README.rst') as readme_file:
9-
# readme = readme_file.read()
8+
with open('README.rst') as readme_file:
9+
readme = readme_file.read()
1010

1111
readme = ""
1212

0 commit comments

Comments
 (0)