Skip to content

Commit a62c21b

Browse files
committed
Update graphql-core to v0.4.7b1.
Finish implementation of Unions.
1 parent 7887a5d commit a62c21b

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

epoxy/metaclasses/union.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
from graphql.core.type.definition import GraphQLUnionType
22

3-
from ..utils.no_implementation_registration import no_implementation_registration
4-
53

64
class UnionMeta(type):
75
def __new__(mcs, name, bases, attrs):
86
if attrs.pop('abstract', False):
97
return super(UnionMeta, mcs).__new__(mcs, name, bases, attrs)
108

11-
with no_implementation_registration():
12-
union_type = GraphQLUnionType(
13-
name,
14-
types=mcs._get_types(),
15-
description=attrs.get('__doc__'),
16-
)
17-
9+
union_type = GraphQLUnionType(
10+
name,
11+
types=mcs._get_types(),
12+
description=attrs.get('__doc__'),
13+
)
1814
mcs._register(union_type)
1915
cls = super(UnionMeta, mcs).__new__(mcs, name, bases, attrs)
2016
cls.T = union_type
@@ -32,4 +28,4 @@ def _get_registry():
3228

3329
@staticmethod
3430
def _get_types():
35-
return None
31+
raise NotImplementedError('_get_types must be implemented in the sub-metaclass')

epoxy/registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ def _register(union):
164164
def _get_registry():
165165
return registry
166166

167-
class Union(six.with_metaclass(RegistryUnionMeta)):
168-
abstract = True
169-
170167
@staticmethod
171168
def _get_types():
172169
return TransformThunkList(types_thunk, get_named_type)
173170

171+
class Union(six.with_metaclass(RegistryUnionMeta)):
172+
abstract = True
173+
174174
return Union
175175

176176
def _create_is_type_of(self, type):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22
import sys
33

4-
required_packages = ['graphql-core>=0.4.7b0']
4+
required_packages = ['graphql-core>=0.4.7b1']
55

66
if sys.version_info <= (2, 7, 0):
77
required_packages.append('enum34>=1.0.4')

tests/test_unions.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from graphql.core import graphql
2+
from epoxy import TypeRegistry
3+
4+
5+
def test_runtime_type_resolution():
6+
R = TypeRegistry()
7+
8+
class Pet(R.Union[R.Dog, R.Cat]):
9+
pass
10+
11+
class Dog(R.ObjectType):
12+
bark = R.String
13+
name = R.String
14+
15+
class Cat(R.ObjectType):
16+
meow = R.String
17+
name = R.String
18+
19+
class Query(R.ObjectType):
20+
pets = R.Pet.List
21+
22+
schema = R.Schema(Query)
23+
24+
data = Query(pets=[
25+
Dog(name='Clifford', bark='Really big bark, because it\'s a really big dog.'),
26+
Cat(name='Garfield', meow='Lasagna')
27+
])
28+
29+
result = graphql(schema, '''
30+
{
31+
pets {
32+
__typename
33+
... on Dog {
34+
name
35+
bark
36+
}
37+
38+
... on Cat {
39+
name
40+
meow
41+
}
42+
}
43+
}
44+
45+
''', data)
46+
assert not result.errors
47+
assert result.data == {
48+
'pets': [{'__typename': 'Dog', 'bark': "Really big bark, because it's a really big dog.", 'name': 'Clifford'},
49+
{'__typename': 'Cat', 'meow': 'Lasagna', 'name': 'Garfield'}]
50+
}

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ whitelist_externals =
77
dir
88
deps =
99
pytest>=2.7.2
10-
graphql-core>=0.4.7b0
10+
graphql-core>=0.4.7b1
1111
six>=1.10.0
1212
pytest-cov
1313
py{py,27,33}: enum34
1414
py{py,27,33,34}: singledispatch
1515
commands =
16-
py{py,27,33,34,35}: py.test {posargs}
16+
py{py,27,33,34,35}: py.test tests {posargs}
1717

1818
[testenv:flake8]
1919
basepython=python3.5

0 commit comments

Comments
 (0)