mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-03 03:43:26 +03:00
allow unions to be used in connections
This commit is contained in:
parent
6c7cd4e4fa
commit
03898007a5
|
@ -12,6 +12,7 @@ from ..types import (AbstractType, Boolean, Enum, Int, Interface, List, NonNull,
|
|||
from ..types.field import Field
|
||||
from ..types.objecttype import ObjectType, ObjectTypeMeta
|
||||
from ..types.options import Options
|
||||
from ..types import Union
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.props import props
|
||||
from .node import is_node
|
||||
|
@ -109,7 +110,7 @@ class IterableConnectionField(Field):
|
|||
@property
|
||||
def type(self):
|
||||
type = super(IterableConnectionField, self).type
|
||||
if is_node(type):
|
||||
if issubclass(type, Union) or is_node(type):
|
||||
connection_type = type.Connection
|
||||
else:
|
||||
connection_type = type
|
||||
|
|
|
@ -24,7 +24,21 @@ class UnionMeta(type):
|
|||
len(options.types) > 0
|
||||
), 'Must provide types for Union {}.'.format(options.name)
|
||||
|
||||
return type.__new__(cls, name, bases, dict(attrs, _meta=options))
|
||||
cls = type.__new__(cls, name, bases, dict(attrs, _meta=options))
|
||||
|
||||
get_connection = getattr(cls, 'get_connection', None)
|
||||
if not get_connection:
|
||||
from graphene.relay.connection import Connection
|
||||
|
||||
class DefaultUnionConnection(Connection):
|
||||
class Meta:
|
||||
node = cls
|
||||
|
||||
cls.Connection = DefaultUnionConnection
|
||||
else:
|
||||
cls.Connection = get_connection()
|
||||
|
||||
return cls
|
||||
|
||||
def __str__(cls): # noqa: N805
|
||||
return cls._meta.name
|
||||
|
|
Loading…
Reference in New Issue
Block a user