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
|
||||
|
||||
|
||||
*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
|
||||
|
|
|
@ -12,9 +12,7 @@ easily.
|
|||
`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 and Mutations), in addition to queries, mutations and subscriptions.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
|
|
@ -24,12 +24,13 @@ class GraphQLSchema(_GraphQLSchema):
|
|||
class Schema(object):
|
||||
_executor = None
|
||||
|
||||
def __init__(self, query=None, mutation=None,
|
||||
def __init__(self, query=None, mutation=None, subscription=None,
|
||||
name='Schema', executor=None):
|
||||
self._types_names = {}
|
||||
self._types = {}
|
||||
self.mutation = mutation
|
||||
self.query = query
|
||||
self.subscription = subscription
|
||||
self.name = name
|
||||
self.executor = executor
|
||||
signals.init_schema.send(self)
|
||||
|
@ -70,8 +71,10 @@ class Schema(object):
|
|||
if not self.query:
|
||||
raise Exception('You have to define a base query type')
|
||||
return GraphQLSchema(
|
||||
self, query=self.T(self.query),
|
||||
mutation=self.T(self.mutation))
|
||||
self,
|
||||
query=self.T(self.query),
|
||||
mutation=self.T(self.mutation),
|
||||
subscription=self.T(self.subscription))
|
||||
|
||||
def register(self, object_type):
|
||||
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=[
|
||||
'six>=1.10.0',
|
||||
'blinker',
|
||||
'graphql-core==0.4.7b2',
|
||||
'graphql-core==0.4.9',
|
||||
'graphql-relay==0.3.3'
|
||||
],
|
||||
tests_require=[
|
||||
|
|
Loading…
Reference in New Issue
Block a user