From 70e8b9592b7af04a929004d76ddcef5b8b9c6a83 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 17 Nov 2015 16:00:50 -0500 Subject: [PATCH] [v0.3.0] Add support for `subscription` type definitions in the Schema & bump graphql to v0.4.9. --- epoxy/registry.py | 5 +++-- setup.py | 4 ++-- tests/test_subscription.py | 29 +++++++++++++++++++++++++++++ tests/test_true.py | 2 -- tox.ini | 2 +- 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 tests/test_subscription.py delete mode 100644 tests/test_true.py diff --git a/epoxy/registry.py b/epoxy/registry.py index 25b3c42..7597e19 100644 --- a/epoxy/registry.py +++ b/epoxy/registry.py @@ -313,11 +313,12 @@ def _add_impl_to_interfaces(self): interface._impls.append(type) - def Schema(self, query, mutation=None): + def Schema(self, query, mutation=None, subscription=None): query = self[query]() mutation = self[mutation]() + subscription = self[subscription]() self._add_impl_to_interfaces() - return GraphQLSchema(query=query, mutation=mutation) + return GraphQLSchema(query=query, mutation=mutation, subscription=subscription) def Mixin(self, mixin_cls, *args, **kwargs): mixin = mixin_cls(self, *args, **kwargs) diff --git a/setup.py b/setup.py index 297433d..83dadb9 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import sys -required_packages = ['graphql-core>=0.4.7b1'] +required_packages = ['graphql-core>=0.4.9'] if sys.version_info <= (2, 7, 0): required_packages.append('enum34>=1.0.4') @@ -11,7 +11,7 @@ setup( name='graphql-epoxy', - version='0.2.1', + version='0.3.0', description='GraphQL implementation for Python', url='https://github.com/graphql-python/graphql-core', download_url='https://github.com/graphql-python/graphql-core/releases', diff --git a/tests/test_subscription.py b/tests/test_subscription.py new file mode 100644 index 0000000..632ce81 --- /dev/null +++ b/tests/test_subscription.py @@ -0,0 +1,29 @@ +from graphql.core import graphql + +from epoxy.registry import TypeRegistry + + +def test_can_define_and_execute_subscription(): + R = TypeRegistry() + + class Query(R.ObjectType): + a = R.Int + + class Subscription(R.ObjectType): + subscribe_to_foo = R.Boolean(args={'id': R.Int}) + + def resolve_subscribe_to_foo(self, obj, args, info): + return args.get('id') == 1 + + Schema = R.Schema(R.Query, subscription=R.Subscription) + + response = graphql(Schema, ''' + subscription { + subscribeToFoo(id: 1) + } + ''') + + assert not response.errors + assert response.data == { + 'subscribeToFoo': True + } diff --git a/tests/test_true.py b/tests/test_true.py deleted file mode 100644 index 1f3b77f..0000000 --- a/tests/test_true.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_true(): - assert True diff --git a/tox.ini b/tox.ini index e6c4d51..2e7b7ff 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ whitelist_externals = dir deps = pytest>=2.7.2 - graphql-core>=0.4.7b1 + graphql-core>=0.4.9 six>=1.10.0 pytest-cov py{py,27,33}: enum34