minor changes

This commit is contained in:
Kacppian 2018-07-28 15:30:08 +05:30
parent 2ce38844a2
commit 863bfcf6b4

View File

@ -9,6 +9,7 @@ from ..types import Boolean, Enum, Int, Interface, List, NonNull, Scalar, String
from ..types.field import Field from ..types.field import Field
from ..types.objecttype import ObjectType, ObjectTypeOptions from ..types.objecttype import ObjectType, ObjectTypeOptions
from .node import is_node from .node import is_node
from ..utils.comparison_helper import raise_assertion_if
class PageInfo(ObjectType): class PageInfo(ObjectType):
@ -46,17 +47,18 @@ class Connection(ObjectType):
@classmethod @classmethod
def __init_subclass_with_meta__(cls, node=None, name=None, **options): def __init_subclass_with_meta__(cls, node=None, name=None, **options):
_meta = ConnectionOptions(cls) _meta = ConnectionOptions(cls)
if not node: error_message = "You have to provide a node in {}.Meta".format(cls.__name__)
raise AssertionError( raise_assertion_if(condition=not node, message=error_message)
"You have to provide a node in {}.Meta".format(cls.__name__)
)
if not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)): error_message = 'Received incompatible node "{}" for Connection {}.'.format(
raise AssertionError( node, cls.__name__
'Received incompatible node "{}" for Connection {}.'.format( )
node, cls.__name__ raise_assertion_if(
) condition=not issubclass(
) node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)
),
error_message=error_message,
)
base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name base_name = re.sub("Connection$", "", name or cls.__name__) or node._meta.name
if not name: if not name:
@ -106,18 +108,20 @@ class IterableConnectionField(Field):
if isinstance(type, NonNull): if isinstance(type, NonNull):
connection_type = type.of_type connection_type = type.of_type
if is_node(connection_type): error_message = """
raise Exception( ConnectionField's now need a explicit ConnectionType for Nodes.
"ConnectionField's now need a explicit ConnectionType for Nodes.\n" Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections
"Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections" """
) raise_assertion_if(
condition=is_node(connection_type), error_message=error_message
)
if not issubclass(connection_type, Connection): error_message = '{} type have to be a subclass of Connection. Received "{}".'.format(
raise AssertionError( self.__class__.__name__, connection_type
'{} type have to be a subclass of Connection. Received "{}".'.format( )
self.__class__.__name__, connection_type raise_assertion_if(
) condition=not issubclass(connection_type, Connection), message=error_message
) )
return type return type
@classmethod @classmethod
@ -125,15 +129,16 @@ class IterableConnectionField(Field):
if isinstance(resolved, connection_type): if isinstance(resolved, connection_type):
return resolved return resolved
if not isinstance(resolved, Iterable): error_message = """
raise AssertionError( Resolved value from the connection field have to be iterable or instance of {}.
""" Received "{}"
Resolved value from the connection field have to be iterable or instance of {}. """.format(
Received "{}" connection_type, resolved
""".format( )
connection_type, resolved raise_assertion_if(
) condition=not isinstance(resolved, Iterable), message=error_message
) )
connection = connection_from_list( connection = connection_from_list(
resolved, resolved,
args, args,