mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-30 01:39:56 +03:00
changed function name
This commit is contained in:
parent
11a3fe901a
commit
b09e4cb6de
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from .comparison_helper import raise_assertion_if_true
|
from .comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
def get_version(version=None):
|
def get_version(version=None):
|
||||||
|
@ -45,11 +45,11 @@ def get_complete_version(version=None):
|
||||||
if version is None:
|
if version is None:
|
||||||
from graphene import VERSION as version
|
from graphene import VERSION as version
|
||||||
else:
|
else:
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=len(version) is not 5,
|
condition=len(version) is not 5,
|
||||||
message="Version needs to be 5"
|
message="Version needs to be 5"
|
||||||
)
|
)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=version[3] not in ("alpha", "beta", "rc", "final"),
|
condition=version[3] not in ("alpha", "beta", "rc", "final"),
|
||||||
message="Release version is unkown"
|
message="Release version is unkown"
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +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_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
class PageInfo(ObjectType):
|
class PageInfo(ObjectType):
|
||||||
|
@ -49,8 +49,8 @@ class Connection(ObjectType):
|
||||||
_meta = ConnectionOptions(cls)
|
_meta = ConnectionOptions(cls)
|
||||||
|
|
||||||
error_message = "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_true(
|
raise_assertion_if(
|
||||||
condition=not node,
|
condition=not node,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class Connection(ObjectType):
|
||||||
node, cls.__name__
|
node, cls.__name__
|
||||||
)
|
)
|
||||||
condition = not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull))
|
condition = not issubclass(node, (Scalar, Enum, ObjectType, Interface, Union, NonNull))
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=condition,
|
condition=condition,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
@ -119,7 +119,7 @@ class IterableConnectionField(Field):
|
||||||
|
|
||||||
error_message = '{} type have to be a subclass of Connection. Received "{}".'
|
error_message = '{} type have to be a subclass of Connection. Received "{}".'
|
||||||
.format(self.__class__.__name__, connection_type)
|
.format(self.__class__.__name__, connection_type)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition= not issubclass(connection_type, Connection),
|
condition= not issubclass(connection_type, Connection),
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from promise import Promise, is_thenable
|
||||||
|
|
||||||
from ..types import Field, InputObjectType, String
|
from ..types import Field, InputObjectType, String
|
||||||
from ..types.mutation import Mutation
|
from ..types.mutation import Mutation
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
class ClientIDMutation(Mutation):
|
class ClientIDMutation(Mutation):
|
||||||
|
@ -19,7 +19,7 @@ class ClientIDMutation(Mutation):
|
||||||
input_class = getattr(cls, "Input", None)
|
input_class = getattr(cls, "Input", None)
|
||||||
base_name = re.sub("Payload$", "", name or cls.__name__)
|
base_name = re.sub("Payload$", "", name or cls.__name__)
|
||||||
|
|
||||||
raise_assertion_if_true(condition=output, message="Can't specify any output")
|
raise_assertion_if(condition=output, message="Can't specify any output")
|
||||||
|
|
||||||
if arguments:
|
if arguments:
|
||||||
raise AssertionError("Can't specify any arguments")
|
raise AssertionError("Can't specify any arguments")
|
||||||
|
|
|
@ -7,7 +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.interface import InterfaceOptions
|
from ..types.interface import InterfaceOptions
|
||||||
from ..types.utils import get_type
|
from ..types.utils import get_type
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class GlobalID(Field):
|
||||||
|
|
||||||
class NodeField(Field):
|
class NodeField(Field):
|
||||||
def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs):
|
def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs):
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition= not issubclass(node, Node),
|
condition= not issubclass(node, Node),
|
||||||
message="NodeField can only operate in Nodes"
|
message="NodeField can only operate in Nodes"
|
||||||
)
|
)
|
||||||
|
@ -103,7 +103,7 @@ class Node(AbstractNode):
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=only_type and (graphene_type is not only_type),
|
condition=only_type and (graphene_type is not only_type),
|
||||||
message="Must receive a {} id.".format(only_type._meta.name)
|
message="Must receive a {} id.".format(only_type._meta.name)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from .dynamic import Dynamic
|
||||||
from .mountedtype import MountedType
|
from .mountedtype import MountedType
|
||||||
from .structures import NonNull
|
from .structures import NonNull
|
||||||
from .utils import get_type
|
from .utils import get_type
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
class Argument(MountedType):
|
class Argument(MountedType):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -73,7 +73,7 @@ def to_arguments(args, extra_args=None):
|
||||||
raise ValueError('Unknown argument "{}".'.format(default_name))
|
raise ValueError('Unknown argument "{}".'.format(default_name))
|
||||||
|
|
||||||
arg_name = default_name or arg.name
|
arg_name = default_name or arg.name
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=arg_name in arguments,
|
condition=arg_name in arguments,
|
||||||
message='More than one Argument have same name "{}".'.format(arg_name)
|
message='More than one Argument have same name "{}".'.format(arg_name)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from ..utils.subclass_with_meta import SubclassWithMeta
|
from ..utils.subclass_with_meta import SubclassWithMeta
|
||||||
from ..utils.trim_docstring import trim_docstring
|
from ..utils.trim_docstring import trim_docstring
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
class BaseOptions(object):
|
class BaseOptions(object):
|
||||||
name = None # type: str
|
name = None # type: str
|
||||||
|
@ -31,7 +31,7 @@ class BaseType(SubclassWithMeta):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None):
|
def __init_subclass_with_meta__(cls, name=None, description=None, _meta=None):
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition="_meta" in cls.__dict__,
|
condition="_meta" in cls.__dict__,
|
||||||
message="Can't assign meta directly"
|
message="Can't assign meta directly"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from aniso8601 import parse_date, parse_datetime, parse_time
|
||||||
from graphql.language import ast
|
from graphql.language import ast
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
class Date(Scalar):
|
class Date(Scalar):
|
||||||
"""
|
"""
|
||||||
|
@ -19,7 +19,7 @@ class Date(Scalar):
|
||||||
def serialize(date):
|
def serialize(date):
|
||||||
if isinstance(date, datetime.datetime):
|
if isinstance(date, datetime.datetime):
|
||||||
date = date.date()
|
date = date.date()
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not isinstance(date, datetime.date),
|
condition=not isinstance(date, datetime.date),
|
||||||
message='Received not compatible date "{}"'.format(repr(date))
|
message='Received not compatible date "{}"'.format(repr(date))
|
||||||
)
|
)
|
||||||
|
@ -48,7 +48,7 @@ class DateTime(Scalar):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def serialize(dt):
|
def serialize(dt):
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not isinstance(dt, (datetime.datetime, datetime.date)),
|
condition=not isinstance(dt, (datetime.datetime, datetime.date)),
|
||||||
message='Received not compatible datetime "{}"'.format(repr(dt))
|
message='Received not compatible datetime "{}"'.format(repr(dt))
|
||||||
)
|
)
|
||||||
|
@ -76,7 +76,7 @@ class Time(Scalar):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def serialize(time):
|
def serialize(time):
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition= not isinstance(time, datetime.time),
|
condition= not isinstance(time, datetime.time),
|
||||||
message='Received not compatible time "{}"'.format(repr(time))
|
message='Received not compatible time "{}"'.format(repr(time))
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ from functools import partial
|
||||||
|
|
||||||
from .mountedtype import MountedType
|
from .mountedtype import MountedType
|
||||||
|
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
class Dynamic(MountedType):
|
class Dynamic(MountedType):
|
||||||
|
@ -14,7 +14,7 @@ class Dynamic(MountedType):
|
||||||
|
|
||||||
def __init__(self, type, with_schema=False, _creation_counter=None):
|
def __init__(self, type, with_schema=False, _creation_counter=None):
|
||||||
super(Dynamic, self).__init__(_creation_counter=_creation_counter)
|
super(Dynamic, self).__init__(_creation_counter=_creation_counter)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not (inspect.isfunction(type) or isinstance(type, partial)),
|
condition=not (inspect.isfunction(type) or isinstance(type, partial)),
|
||||||
message="type is expected to be a function or an instance of partial"
|
message="type is expected to be a function or an instance of partial"
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from .mountedtype import MountedType
|
||||||
from .structures import NonNull
|
from .structures import NonNull
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
from .utils import get_type
|
from .utils import get_type
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
base_type = type
|
base_type = type
|
||||||
|
|
||||||
|
@ -36,17 +36,17 @@ class Field(MountedType):
|
||||||
):
|
):
|
||||||
super(Field, self).__init__(_creation_counter=_creation_counter)
|
super(Field, self).__init__(_creation_counter=_creation_counter)
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=args and not isinstance(args, Mapping),
|
condition=args and not isinstance(args, Mapping),
|
||||||
message='Arguments in a field have to be a mapping, received "{}".'.format(args)
|
message='Arguments in a field have to be a mapping, received "{}".'.format(args)
|
||||||
)
|
)
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=source and resolver,
|
condition=source and resolver,
|
||||||
message="A Field cannot have a source and a resolver in at the same time."
|
message="A Field cannot have a source and a resolver in at the same time."
|
||||||
)
|
)
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=callable(default_value),
|
condition=callable(default_value),
|
||||||
message='The default value can not be a function but received "{}".'.format(base_type(default_value)
|
message='The default value can not be a function but received "{}".'.format(base_type(default_value)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from ..utils.orderedtype import OrderedType
|
from ..utils.orderedtype import OrderedType
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
|
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
class MountedType(OrderedType):
|
class MountedType(OrderedType):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -9,7 +9,7 @@ class MountedType(OrderedType):
|
||||||
"""
|
"""
|
||||||
Mount the UnmountedType instance
|
Mount the UnmountedType instance
|
||||||
"""
|
"""
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not isinstance(unmounted, UnmountedType),
|
condition=not isinstance(unmounted, UnmountedType),
|
||||||
message="{} can't mount {}".format(cls.__name__, repr(unmounted)
|
message="{} can't mount {}".format(cls.__name__, repr(unmounted)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from .field import Field
|
||||||
from .interface import Interface
|
from .interface import Interface
|
||||||
from .utils import yank_fields_from_attrs
|
from .utils import yank_fields_from_attrs
|
||||||
|
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
# For static type checking with Mypy
|
# For static type checking with Mypy
|
||||||
MYPY = False
|
MYPY = False
|
||||||
|
@ -54,7 +54,7 @@ class ObjectType(BaseType):
|
||||||
Please use one or other.
|
Please use one or other.
|
||||||
""".format(name=cls.__name__)
|
""".format(name=cls.__name__)
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=possible_types and cls.is_type_of,
|
condition=possible_types and cls.is_type_of,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
def attr_resolver(attname, default_value, root, info, **args):
|
def attr_resolver(attname, default_value, root, info, **args):
|
||||||
return getattr(root, attname, default_value)
|
return getattr(root, attname, default_value)
|
||||||
|
@ -14,7 +14,7 @@ default_resolver = attr_resolver
|
||||||
def set_default_resolver(resolver):
|
def set_default_resolver(resolver):
|
||||||
global default_resolver
|
global default_resolver
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not callable(resolver),
|
condition=not callable(resolver),
|
||||||
message="Received non-callable resolver."
|
message="Received non-callable resolver."
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,14 +13,14 @@ from graphql.utils.schema_printer import print_schema
|
||||||
from .definitions import GrapheneGraphQLType
|
from .definitions import GrapheneGraphQLType
|
||||||
from .objecttype import ObjectType
|
from .objecttype import ObjectType
|
||||||
from .typemap import TypeMap, is_graphene_type
|
from .typemap import TypeMap, is_graphene_type
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
def assert_valid_root_type(_type):
|
def assert_valid_root_type(_type):
|
||||||
if _type is None:
|
if _type is None:
|
||||||
return
|
return
|
||||||
is_graphene_objecttype = inspect.isclass(_type) and issubclass(_type, ObjectType)
|
is_graphene_objecttype = inspect.isclass(_type) and issubclass(_type, ObjectType)
|
||||||
is_graphql_objecttype = isinstance(_type, GraphQLObjectType)
|
is_graphql_objecttype = isinstance(_type, GraphQLObjectType)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not (is_graphene_objecttype or is_graphql_objecttype),
|
condition=not (is_graphene_objecttype or is_graphql_objecttype),
|
||||||
message="Type {} is not a valid ObjectType.".format(_type)
|
message="Type {} is not a valid ObjectType.".format(_type)
|
||||||
)
|
)
|
||||||
|
@ -54,7 +54,7 @@ class Schema(GraphQLSchema):
|
||||||
if directives is None:
|
if directives is None:
|
||||||
directives = [GraphQLIncludeDirective, GraphQLSkipDirective]
|
directives = [GraphQLIncludeDirective, GraphQLSkipDirective]
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not all(isinstance(d, GraphQLDirective) for d in directives),
|
condition=not all(isinstance(d, GraphQLDirective) for d in directives),
|
||||||
message="Schema directives must be List[GraphQLDirective] if provided but got: {}.".format(directives)
|
message="Schema directives must be List[GraphQLDirective] if provided but got: {}.".format(directives)
|
||||||
)
|
)
|
||||||
|
@ -92,14 +92,14 @@ class Schema(GraphQLSchema):
|
||||||
if is_graphene_type(_type):
|
if is_graphene_type(_type):
|
||||||
graphql_type = self.get_type(_type._meta.name)
|
graphql_type = self.get_type(_type._meta.name)
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not graphql_type,
|
condition=not graphql_type,
|
||||||
message="Type {} not found in this schema.".format(_type._meta.name)
|
message="Type {} not found in this schema.".format(_type._meta.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
error_message = "The type {} does not match with the associated graphene type {}."
|
error_message = "The type {} does not match with the associated graphene type {}."
|
||||||
.format(_type, graphql_type.graphene_type)
|
.format(_type, graphql_type.graphene_type)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=graphql_type.graphene_type is not _type,
|
condition=graphql_type.graphene_type is not _type,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
|
|
@ -40,7 +40,7 @@ from .scalars import ID, Boolean, Float, Int, Scalar, String
|
||||||
from .structures import List, NonNull
|
from .structures import List, NonNull
|
||||||
from .union import Union
|
from .union import Union
|
||||||
from .utils import get_field_as
|
from .utils import get_field_as
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
def is_graphene_type(_type):
|
def is_graphene_type(_type):
|
||||||
|
@ -61,14 +61,14 @@ def resolve_type(resolve_type_func, map, type_name, root, info):
|
||||||
|
|
||||||
if inspect.isclass(_type) and issubclass(_type, ObjectType):
|
if inspect.isclass(_type) and issubclass(_type, ObjectType):
|
||||||
graphql_type = map.get(_type._meta.name)
|
graphql_type = map.get(_type._meta.name)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not graphql_type,
|
condition=not graphql_type,
|
||||||
message="Can't find type {} in schema".format(_type._meta.name)
|
message="Can't find type {} in schema".format(_type._meta.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
error_message = "The type {} does not match with the associated graphene type {}."
|
error_message = "The type {} does not match with the associated graphene type {}."
|
||||||
.format( _type, graphql_type.graphene_type)
|
.format( _type, graphql_type.graphene_type)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=graphql_type.graphene_type is not _type,
|
condition=graphql_type.graphene_type is not _type,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
@ -105,7 +105,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
if isinstance(_type, GrapheneGraphQLType):
|
if isinstance(_type, GrapheneGraphQLType):
|
||||||
error_message = "Found different types with the same name in the schema: {}, {}."
|
error_message = "Found different types with the same name in the schema: {}, {}."
|
||||||
.format(_type.graphene_type, type)
|
.format(_type.graphene_type, type)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=_type.graphene_type is not type,
|
condition=_type.graphene_type is not type,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
@ -187,7 +187,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
if isinstance(_type, GrapheneGraphQLType):
|
if isinstance(_type, GrapheneGraphQLType):
|
||||||
error_message = "Found different types with the same name in the schema: {}, {}."
|
error_message = "Found different types with the same name in the schema: {}, {}."
|
||||||
.format(_type.graphene_type, type)
|
.format(_type.graphene_type, type)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=_type.graphene_type is not type,
|
condition=_type.graphene_type is not type,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
@ -200,7 +200,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
internal_type = map[interface._meta.name]
|
internal_type = map[interface._meta.name]
|
||||||
error_message = "Found different types with the same name in the schema: {}, {}."
|
error_message = "Found different types with the same name in the schema: {}, {}."
|
||||||
.format(internal_type.graphene_type, interface)
|
.format(internal_type.graphene_type, interface)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=internal_type.graphene_type is not interface,
|
condition=internal_type.graphene_type is not interface,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
@ -229,7 +229,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
if isinstance(_type, GrapheneInterfaceType):
|
if isinstance(_type, GrapheneInterfaceType):
|
||||||
error_message = "Found different types with the same name in the schema: {}, {}."
|
error_message = "Found different types with the same name in the schema: {}, {}."
|
||||||
.format(_type.graphene_type, type)
|
.format(_type.graphene_type, type)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition= _type.graphene_type is not type,
|
condition= _type.graphene_type is not type,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
@ -273,7 +273,7 @@ class TypeMap(GraphQLTypeMap):
|
||||||
internal_type = map[objecttype._meta.name]
|
internal_type = map[objecttype._meta.name]
|
||||||
error_message = "Found different types with the same name in the schema: {}, {}."
|
error_message = "Found different types with the same name in the schema: {}, {}."
|
||||||
.format(internal_type.graphene_type, objecttype)
|
.format(internal_type.graphene_type, objecttype)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=internal_type.graphene_type is not objecttype,
|
condition=internal_type.graphene_type is not objecttype,
|
||||||
message=error_message
|
message=error_message
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from .base import BaseOptions, BaseType
|
from .base import BaseOptions, BaseType
|
||||||
from .unmountedtype import UnmountedType
|
from .unmountedtype import UnmountedType
|
||||||
|
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
# For static type checking with Mypy
|
# For static type checking with Mypy
|
||||||
MYPY = False
|
MYPY = False
|
||||||
|
@ -26,7 +26,7 @@ class Union(UnmountedType, BaseType):
|
||||||
@classmethod
|
@classmethod
|
||||||
def __init_subclass_with_meta__(cls, types=None, **options):
|
def __init_subclass_with_meta__(cls, types=None, **options):
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not (isinstance(types, (list, tuple)) and len(types) > 0,
|
condition=not (isinstance(types, (list, tuple)) and len(types) > 0,
|
||||||
message="Must provide types for Union {name}.".format(name=cls.__name__)
|
message="Must provide types for Union {name}.".format(name=cls.__name__)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from uuid import UUID as _UUID
|
||||||
from graphql.language import ast
|
from graphql.language import ast
|
||||||
|
|
||||||
from .scalars import Scalar
|
from .scalars import Scalar
|
||||||
from ..utils.comparison_helper import raise_assertion_if_true
|
from ..utils.comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
class UUID(Scalar):
|
class UUID(Scalar):
|
||||||
"""UUID"""
|
"""UUID"""
|
||||||
|
@ -14,7 +14,7 @@ class UUID(Scalar):
|
||||||
def serialize(uuid):
|
def serialize(uuid):
|
||||||
if isinstance(uuid, str):
|
if isinstance(uuid, str):
|
||||||
uuid = _UUID(uuid)
|
uuid = _UUID(uuid)
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=not isinstance(uuid, _UUID),
|
condition=not isinstance(uuid, _UUID),
|
||||||
message="Expected UUID instance, received {}".format(uuid)
|
message="Expected UUID instance, received {}".format(uuid)
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import six
|
||||||
|
|
||||||
from ..pyutils.compat import func_name, signature
|
from ..pyutils.compat import func_name, signature
|
||||||
from .deprecated import warn_deprecation
|
from .deprecated import warn_deprecation
|
||||||
from .comparison_helper import raise_assertion_if_true
|
from .comparison_helper import raise_assertion_if
|
||||||
|
|
||||||
|
|
||||||
def annotate(_func=None, _trigger_warning=True, **annotations):
|
def annotate(_func=None, _trigger_warning=True, **annotations):
|
||||||
|
@ -27,7 +27,7 @@ def annotate(_func=None, _trigger_warning=True, **annotations):
|
||||||
assertion_message = 'The key {key} is not a function parameter in the function "{func_name}".'
|
assertion_message = 'The key {key} is not a function parameter in the function "{func_name}".'
|
||||||
.format(key=key, func_name=func_name(_func)
|
.format(key=key, func_name=func_name(_func)
|
||||||
|
|
||||||
raise_assertion_if_true(
|
raise_assertion_if(
|
||||||
condition=func_param is None,
|
condition=func_param is None,
|
||||||
message=assertion_message
|
message=assertion_message
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
def raise_assertion_if_true(condition=None, message=None):
|
def raise_assertion_if(condition=None, message=None):
|
||||||
if condition:
|
if condition:
|
||||||
raise AssertionError(message)
|
raise AssertionError(message)
|
|
@ -44,9 +44,9 @@ class SubclassWithMeta(six.with_metaclass(SubclassWithMeta_Meta)):
|
||||||
error_message = """
|
error_message = """
|
||||||
Abstract types can only contain the abstract attribute.
|
Abstract types can only contain the abstract attribute.
|
||||||
Received: abstract, {option_keys}
|
Received: abstract, {option_keys}
|
||||||
""".format(option_keys=", ".join(options.keys())
|
""".format(option_keys=", ".join(options.keys())
|
||||||
|
|
||||||
raise_assertion_if_true(condition=options and abstract, message=error_message)
|
raise_assertion_if(condition=options and abstract, message=error_message)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
super_class = super(cls, cls)
|
super_class = super(cls, cls)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user