mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Added subscription support. Fixed #35
This commit is contained in:
parent
4a591354f1
commit
b91ae4b0fb
|
@ -8,7 +8,7 @@ Graphene is a Python library for building GraphQL schemas/types fast and easily.
|
||||||
- **Django:** Automatic *Django model* mapping to Graphene Types. Check a fully working [Django](http://github.com/graphql-python/swapi-graphene) implementation
|
- **Django:** Automatic *Django model* mapping to Graphene Types. Check a fully working [Django](http://github.com/graphql-python/swapi-graphene) implementation
|
||||||
|
|
||||||
|
|
||||||
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Mutations, Scalars, Unions and Relay (Nodes, Connections and Mutations).
|
*What is supported in this Python version?* **Everything**: Interfaces, ObjectTypes, Scalars, Unions and Relay (Nodes, Connections), in addition to queries, mutations and subscriptions.
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
|
@ -12,9 +12,7 @@ easily.
|
||||||
`Django <http://github.com/graphql-python/swapi-graphene>`__
|
`Django <http://github.com/graphql-python/swapi-graphene>`__
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
*What is supported in this Python version?* **Everything**: Interfaces,
|
*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.
|
||||||
ObjectTypes, Mutations, Scalars, Unions and Relay (Nodes, Connections
|
|
||||||
and Mutations).
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -24,12 +24,13 @@ class GraphQLSchema(_GraphQLSchema):
|
||||||
class Schema(object):
|
class Schema(object):
|
||||||
_executor = None
|
_executor = None
|
||||||
|
|
||||||
def __init__(self, query=None, mutation=None,
|
def __init__(self, query=None, mutation=None, subscription=None,
|
||||||
name='Schema', executor=None):
|
name='Schema', executor=None):
|
||||||
self._types_names = {}
|
self._types_names = {}
|
||||||
self._types = {}
|
self._types = {}
|
||||||
self.mutation = mutation
|
self.mutation = mutation
|
||||||
self.query = query
|
self.query = query
|
||||||
|
self.subscription = subscription
|
||||||
self.name = name
|
self.name = name
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
signals.init_schema.send(self)
|
signals.init_schema.send(self)
|
||||||
|
@ -70,8 +71,10 @@ class Schema(object):
|
||||||
if not self.query:
|
if not self.query:
|
||||||
raise Exception('You have to define a base query type')
|
raise Exception('You have to define a base query type')
|
||||||
return GraphQLSchema(
|
return GraphQLSchema(
|
||||||
self, query=self.T(self.query),
|
self,
|
||||||
mutation=self.T(self.mutation))
|
query=self.T(self.query),
|
||||||
|
mutation=self.T(self.mutation),
|
||||||
|
subscription=self.T(self.subscription))
|
||||||
|
|
||||||
def register(self, object_type):
|
def register(self, object_type):
|
||||||
type_name = object_type._meta.type_name
|
type_name = object_type._meta.type_name
|
||||||
|
|
29
graphene/core/tests/test_subscription.py
Normal file
29
graphene/core/tests/test_subscription.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import graphene
|
||||||
|
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
base = graphene.String()
|
||||||
|
|
||||||
|
|
||||||
|
class Subscription(graphene.ObjectType):
|
||||||
|
subscribe_to_foo = graphene.Boolean(id=graphene.Int())
|
||||||
|
|
||||||
|
def resolve_subscribe_to_foo(self, args, info):
|
||||||
|
return args.get('id') == 1
|
||||||
|
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query, subscription=Subscription)
|
||||||
|
|
||||||
|
|
||||||
|
def test_execute_subscription():
|
||||||
|
query = '''
|
||||||
|
subscription {
|
||||||
|
subscribeToFoo(id: 1)
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
expected = {
|
||||||
|
'subscribeToFoo': True
|
||||||
|
}
|
||||||
|
result = schema.execute(query)
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == expected
|
2
setup.py
2
setup.py
|
@ -56,7 +56,7 @@ setup(
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'six>=1.10.0',
|
'six>=1.10.0',
|
||||||
'blinker',
|
'blinker',
|
||||||
'graphql-core==0.4.7b2',
|
'graphql-core==0.4.9',
|
||||||
'graphql-relay==0.3.3'
|
'graphql-relay==0.3.3'
|
||||||
],
|
],
|
||||||
tests_require=[
|
tests_require=[
|
||||||
|
|
Loading…
Reference in New Issue
Block a user