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.objecttype import ObjectType, ObjectTypeOptions
from .node import is_node
from ..utils.comparison_helper import raise_assertion_if
class PageInfo(ObjectType):
@ -46,17 +47,18 @@ class Connection(ObjectType):
@classmethod
def __init_subclass_with_meta__(cls, node=None, name=None, **options):
_meta = ConnectionOptions(cls)
if not node:
raise AssertionError(
"You have to provide a node in {}.Meta".format(cls.__name__)
)
error_message = "You have to provide a node in {}.Meta".format(cls.__name__)
raise_assertion_if(condition=not node, message=error_message)
if not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)):
raise AssertionError(
'Received incompatible node "{}" for Connection {}.'.format(
node, cls.__name__
)
)
error_message = '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
if not name:
@ -106,18 +108,20 @@ class IterableConnectionField(Field):
if isinstance(type, NonNull):
connection_type = type.of_type
if is_node(connection_type):
raise Exception(
"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"
)
error_message = """
ConnectionField's now need a explicit ConnectionType for Nodes.
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):
raise AssertionError(
'{} type have to be a subclass of Connection. Received "{}".'.format(
self.__class__.__name__, connection_type
)
)
error_message = '{} 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
@classmethod
@ -125,15 +129,16 @@ class IterableConnectionField(Field):
if isinstance(resolved, connection_type):
return resolved
if not isinstance(resolved, Iterable):
raise AssertionError(
"""
Resolved value from the connection field have to be iterable or instance of {}.
Received "{}"
""".format(
connection_type, resolved
)
)
error_message = """
Resolved value from the connection field have to be iterable or instance of {}.
Received "{}"
""".format(
connection_type, resolved
)
raise_assertion_if(
condition=not isinstance(resolved, Iterable), message=error_message
)
connection = connection_from_list(
resolved,
args,