Skip to content

Commit

Permalink
Improved Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Nov 17, 2017
1 parent d651051 commit 991bafe
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 15 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

Websocket server for GraphQL subscriptions.

# Installation instructions

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

```shell
git clone https://github.com/graphql-python/graphql-ws.git
cd graphql-ws
# Installation instructions

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

# Demo time!
cd examples
python aio.py
```bash
pip install graphql-ws
```

## Setup
## Examples

### aiohttp

Expand Down Expand Up @@ -69,6 +64,7 @@ class Subscription(graphene.ObjectType):
schema = graphene.Schema(query=Query, subscription=Subscription)
```

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

### Gevent

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

schema = graphene.Schema(query=Query, subscription=Subscription)
```

You can see a full example here: https://github.com/graphql-python/graphql-ws/tree/master/examples/flask_gevent
113 changes: 113 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
GraphQL WS
==========

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>`__

Installation instructions
=========================

For instaling graphql-ws, just run this command in your shell

.. code:: bash
pip install graphql-ws
Examples
--------

aiohttp
~~~~~~~

For setting up, just plug into your aiohttp server.

.. code:: python
from graphql_ws.aiohttp import AiohttpSubscriptionServer
subscription_server = AiohttpSubscriptionServer(schema)
async def subscriptions(request):
ws = web.WebSocketResponse(protocols=('graphql-ws',))
await ws.prepare(request)
await subscription_server.handle(ws)
return ws
app = web.Application()
app.router.add_get('/subscriptions', subscriptions)
web.run_app(app, port=8000)
And then, plug into a subscribable schema:

.. code:: python
import asyncio
import graphene
class Query(graphene.ObjectType):
base = graphene.String()
class Subscription(graphene.ObjectType):
count_seconds = graphene.Float(up_to=graphene.Int())
async def resolve_count_seconds(root, info, up_to):
for i in range(up_to):
yield i
await asyncio.sleep(1.)
yield up_to
schema = graphene.Schema(query=Query, subscription=Subscription)
You can see a full example here:
https://github.com/graphql-python/graphql-ws/tree/master/examples/aiohttp

Gevent
~~~~~~

For setting up, just plug into your Gevent server.

.. code:: python
subscription_server = GeventSubscriptionServer(schema)
app.app_protocol = lambda environ_path_info: 'graphql-ws'
@sockets.route('/subscriptions')
def echo_socket(ws):
subscription_server.handle(ws)
return []
And then, plug into a subscribable schema:

.. code:: python
import graphene
from rx import Observable
class Query(graphene.ObjectType):
base = graphene.String()
class Subscription(graphene.ObjectType):
count_seconds = graphene.Float(up_to=graphene.Int())
async def resolve_count_seconds(root, info, up_to=5):
return Observable.interval(1000)\
.map(lambda i: "{0}".format(i))\
.take_while(lambda i: int(i) <= up_to)
schema = graphene.Schema(query=Query, subscription=Subscription)
You can see a full example here:
https://github.com/graphql-python/graphql-ws/tree/master/examples/flask\_gevent
3 changes: 3 additions & 0 deletions bin/convert_documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

pandoc README.md --from markdown --to rst -s -o README.rst
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from setuptools import setup, find_packages

# with open('README.rst') as readme_file:
# readme = readme_file.read()
with open('README.rst') as readme_file:
readme = readme_file.read()

readme = ""

Expand Down

0 comments on commit 991bafe

Please sign in to comment.