Skip to content

Commit d6968c2

Browse files
author
Jonathan Kim
committed
Raise better error if type is missing from schema
1 parent 5036d16 commit d6968c2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

graphene/types/tests/test_typemap.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12

23
from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
34
GraphQLField, GraphQLInputObjectField,
@@ -13,7 +14,7 @@
1314
from ..interface import Interface
1415
from ..objecttype import ObjectType
1516
from ..scalars import String, Int
16-
from ..typemap import TypeMap
17+
from ..typemap import TypeMap, resolve_type
1718

1819

1920
def test_enum():
@@ -232,3 +233,22 @@ class Meta:
232233
assert graphql_type.is_type_of
233234
assert graphql_type.is_type_of({}, None) is True
234235
assert graphql_type.is_type_of(MyObjectType(), None) is False
236+
237+
238+
def test_resolve_type_with_missing_type():
239+
class MyObjectType(ObjectType):
240+
foo_bar = String()
241+
242+
class MyOtherObjectType(ObjectType):
243+
fizz_buzz = String()
244+
245+
def resolve_type_func(root, info):
246+
return MyOtherObjectType
247+
248+
typemap = TypeMap([MyObjectType])
249+
with pytest.raises(AssertionError) as excinfo:
250+
resolve_type(
251+
resolve_type_func, typemap, 'MyOtherObjectType', {}, {}
252+
)
253+
254+
assert 'MyOtherObjectTyp' in str(excinfo.value)

graphene/types/typemap.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def resolve_type(resolve_type_func, map, type_name, root, info):
4646

4747
if inspect.isclass(_type) and issubclass(_type, ObjectType):
4848
graphql_type = map.get(_type._meta.name)
49-
assert graphql_type and graphql_type.graphene_type == _type, (
49+
assert graphql_type, "Can't find type {} in schema".format(
50+
_type._meta.name
51+
)
52+
assert graphql_type.graphene_type == _type, (
5053
'The type {} does not match with the associated graphene type {}.'
5154
).format(_type, graphql_type.graphene_type)
5255
return graphql_type

0 commit comments

Comments
 (0)