mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-27 08:19:45 +03:00
can query a union type
This commit is contained in:
parent
078230ad49
commit
467daaa1d6
|
@ -7,6 +7,7 @@ from graphql_relay import from_global_id, to_global_id
|
||||||
from ..types import ID, Field, Interface, ObjectType
|
from ..types import ID, Field, Interface, ObjectType
|
||||||
from ..types.utils import get_type
|
from ..types.utils import get_type
|
||||||
from ..types.interface import InterfaceMeta
|
from ..types.interface import InterfaceMeta
|
||||||
|
from ..types.union import UnionMeta
|
||||||
|
|
||||||
|
|
||||||
def is_node(objecttype):
|
def is_node(objecttype):
|
||||||
|
@ -98,9 +99,15 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if only_type:
|
if only_type:
|
||||||
assert graphene_type == only_type, (
|
if graphene_type != only_type and isinstance(only_type, UnionMeta):
|
||||||
'Must receive an {} id.'
|
union_types = only_type._meta.types
|
||||||
).format(graphene_type._meta.name)
|
assert graphene_type in union_types, (
|
||||||
|
'Must receive one of {} id.'
|
||||||
|
).format(', '.join(map(lambda t: t._meta.name, union_types)))
|
||||||
|
else:
|
||||||
|
assert graphene_type == only_type, (
|
||||||
|
'Must receive an {} id.'
|
||||||
|
).format(graphene_type._meta.name)
|
||||||
|
|
||||||
# We make sure the ObjectType implements the "Node" interface
|
# We make sure the ObjectType implements the "Node" interface
|
||||||
if cls not in graphene_type._meta.interfaces:
|
if cls not in graphene_type._meta.interfaces:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user