mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 19:13:57 +03:00
Merge pull request #635 from jkimbo/error-missing-type
Raise better error if type is missing from schema
This commit is contained in:
commit
94d5e345a1
|
@ -1,3 +1,4 @@
|
|||
import pytest
|
||||
|
||||
from graphql.type import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
|
||||
GraphQLField, GraphQLInputObjectField,
|
||||
|
@ -13,7 +14,7 @@ from ..inputobjecttype import InputObjectType
|
|||
from ..interface import Interface
|
||||
from ..objecttype import ObjectType
|
||||
from ..scalars import String, Int
|
||||
from ..typemap import TypeMap
|
||||
from ..typemap import TypeMap, resolve_type
|
||||
|
||||
|
||||
def test_enum():
|
||||
|
@ -232,3 +233,22 @@ def test_objecttype_with_possible_types():
|
|||
assert graphql_type.is_type_of
|
||||
assert graphql_type.is_type_of({}, None) is True
|
||||
assert graphql_type.is_type_of(MyObjectType(), None) is False
|
||||
|
||||
|
||||
def test_resolve_type_with_missing_type():
|
||||
class MyObjectType(ObjectType):
|
||||
foo_bar = String()
|
||||
|
||||
class MyOtherObjectType(ObjectType):
|
||||
fizz_buzz = String()
|
||||
|
||||
def resolve_type_func(root, info):
|
||||
return MyOtherObjectType
|
||||
|
||||
typemap = TypeMap([MyObjectType])
|
||||
with pytest.raises(AssertionError) as excinfo:
|
||||
resolve_type(
|
||||
resolve_type_func, typemap, 'MyOtherObjectType', {}, {}
|
||||
)
|
||||
|
||||
assert 'MyOtherObjectTyp' in str(excinfo.value)
|
||||
|
|
|
@ -46,7 +46,10 @@ def resolve_type(resolve_type_func, map, type_name, root, info):
|
|||
|
||||
if inspect.isclass(_type) and issubclass(_type, ObjectType):
|
||||
graphql_type = map.get(_type._meta.name)
|
||||
assert graphql_type and graphql_type.graphene_type == _type, (
|
||||
assert graphql_type, "Can't find type {} in schema".format(
|
||||
_type._meta.name
|
||||
)
|
||||
assert graphql_type.graphene_type == _type, (
|
||||
'The type {} does not match with the associated graphene type {}.'
|
||||
).format(_type, graphql_type.graphene_type)
|
||||
return graphql_type
|
||||
|
|
Loading…
Reference in New Issue
Block a user