Skip to content

Commit b91ae4b

Browse files
committed
Added subscription support. Fixed #35
1 parent 4a59135 commit b91ae4b

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Graphene is a Python library for building GraphQL schemas/types fast and easily.
88
- **Django:** Automatic *Django model* mapping to Graphene Types. Check a fully working [Django](http://github.com/graphql-python/swapi-graphene) implementation
99

1010

11-
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Mutations, Scalars, Unions and Relay (Nodes, Connections and Mutations).
11+
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Scalars, Unions and Relay (Nodes, Connections), in addition to queries, mutations and subscriptions.
1212

1313

1414
## Installation

README.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ easily.
1212
`Django <http://github.com/graphql-python/swapi-graphene>`__
1313
implementation
1414

15-
*What is supported in this Python version?* **Everything**: Interfaces,
16-
ObjectTypes, Mutations, Scalars, Unions and Relay (Nodes, Connections
17-
and Mutations).
15+
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Scalars, Unions and Relay (Nodes, Connections and Mutations), in addition to queries, mutations and subscriptions.
1816

1917
Installation
2018
------------

graphene/core/schema.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ def __init__(self, schema, *args, **kwargs):
2424
class Schema(object):
2525
_executor = None
2626

27-
def __init__(self, query=None, mutation=None,
27+
def __init__(self, query=None, mutation=None, subscription=None,
2828
name='Schema', executor=None):
2929
self._types_names = {}
3030
self._types = {}
3131
self.mutation = mutation
3232
self.query = query
33+
self.subscription = subscription
3334
self.name = name
3435
self.executor = executor
3536
signals.init_schema.send(self)
@@ -70,8 +71,10 @@ def schema(self):
7071
if not self.query:
7172
raise Exception('You have to define a base query type')
7273
return GraphQLSchema(
73-
self, query=self.T(self.query),
74-
mutation=self.T(self.mutation))
74+
self,
75+
query=self.T(self.query),
76+
mutation=self.T(self.mutation),
77+
subscription=self.T(self.subscription))
7578

7679
def register(self, object_type):
7780
type_name = object_type._meta.type_name
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import graphene
2+
3+
4+
class Query(graphene.ObjectType):
5+
base = graphene.String()
6+
7+
8+
class Subscription(graphene.ObjectType):
9+
subscribe_to_foo = graphene.Boolean(id=graphene.Int())
10+
11+
def resolve_subscribe_to_foo(self, args, info):
12+
return args.get('id') == 1
13+
14+
15+
schema = graphene.Schema(query=Query, subscription=Subscription)
16+
17+
18+
def test_execute_subscription():
19+
query = '''
20+
subscription {
21+
subscribeToFoo(id: 1)
22+
}
23+
'''
24+
expected = {
25+
'subscribeToFoo': True
26+
}
27+
result = schema.execute(query)
28+
assert not result.errors
29+
assert result.data == expected

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def run_tests(self):
5656
install_requires=[
5757
'six>=1.10.0',
5858
'blinker',
59-
'graphql-core==0.4.7b2',
59+
'graphql-core==0.4.9',
6060
'graphql-relay==0.3.3'
6161
],
6262
tests_require=[

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ deps=
88
django>=1.8.0,<1.9
99
pytest-django
1010
graphql-django-view>=1.0.0
11-
graphql-core==0.4.7b2
11+
graphql-core==0.4.9
1212
graphql-relay==0.3.3
1313
six
1414
blinker

0 commit comments

Comments
 (0)