Autolint all the files

This commit is contained in:
Syrus Akbary 2016-06-14 22:27:25 -07:00
parent 76ecd895e1
commit c74a75133e
40 changed files with 295 additions and 214 deletions

View File

@ -1,10 +1,9 @@
from ..data import setup from ..schema import Droid
from ..schema import schema, Droid
def test_query_types(): def test_query_types():
graphql_type = Droid._meta.graphql_type graphql_type = Droid._meta.graphql_type
fields = graphql_type.get_fields() fields = graphql_type.get_fields()
assert fields['friends'].parent == Droid assert fields['friends'].parent == Droid
assert fields assert fields

View File

@ -1,5 +1,5 @@
import graphene import graphene
from graphene import implements, relay, resolve_only_args from graphene import relay, resolve_only_args
from .data import create_ship, get_empire, get_faction, get_rebels, get_ship from .data import create_ship, get_empire, get_faction, get_rebels, get_ship
@ -65,5 +65,4 @@ class Mutation(graphene.ObjectType):
introduce_ship = IntroduceShip.Field() introduce_ship = IntroduceShip.Field()
schema = graphene.Schema(query=Query, mutation=Mutation) schema = graphene.Schema(query=Query, mutation=Mutation)

View File

@ -14,4 +14,22 @@ from .types import (
) )
from .utils.resolve_only_args import resolve_only_args from .utils.resolve_only_args import resolve_only_args
__all__ = ['ObjectType', 'InputObjectType', 'Interface', 'implements', 'Field', 'InputField', 'Schema', 'Scalar', 'String', 'ID', 'Int', 'Float', 'Enum', 'Boolean', 'List','NonNull', 'Argument','resolve_only_args'] __all__ = [
'ObjectType',
'InputObjectType',
'Interface',
'implements',
'Field',
'InputField',
'Schema',
'Scalar',
'String',
'ID',
'Int',
'Float',
'Enum',
'Boolean',
'List',
'NonNull',
'Argument',
'resolve_only_args']

View File

@ -1,3 +1,9 @@
from .node import Node from .node import Node
from .mutation import ClientIDMutation from .mutation import ClientIDMutation
from .connection import Connection from .connection import Connection
__all__ = [
'Node',
'ClientIDMutation',
'Connection',
]

View File

@ -1,23 +1,17 @@
import re import re
from collections import Iterable from collections import Iterable
import six import six
from graphql_relay import connection_definitions, connection_from_list from graphql_relay import connection_definitions, connection_from_list
from ..types.field import Field from ..types.field import Field
from ..types.objecttype import ObjectType, ObjectTypeMeta from ..types.objecttype import ObjectType, ObjectTypeMeta
from ..utils.props import props
from ..types.field import Field, InputField
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields
from ..utils.props import props
from ..types.objecttype import ObjectType
from ..utils.is_base_type import is_base_type
from ..types.options import Options from ..types.options import Options
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from ..utils.props import props
class ConnectionMeta(ObjectTypeMeta): class ConnectionMeta(ObjectTypeMeta):
@ -69,7 +63,7 @@ class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
class IterableConnectionField(Field): class IterableConnectionField(Field):
# def __init__(self, type, *args, **kwargs): # def __init__(self, type, *args, **kwargs):
# if # if
def resolver(self, root, args, context, info): def resolver(self, root, args, context, info):
iterable = super(ConnectionField, self).resolver(root, args, context, info) iterable = super(ConnectionField, self).resolver(root, args, context, info)

View File

@ -1,19 +1,18 @@
from functools import partial from functools import partial
import six import six
from graphql_relay import mutation_with_client_mutation_id from graphql_relay import mutation_with_client_mutation_id
from ..types.mutation import Mutation, MutationMeta
from ..types.inputobjecttype import InputObjectType
from ..types.field import Field, InputField from ..types.field import Field, InputField
from ..utils.get_fields import get_fields from ..types.inputobjecttype import InputObjectType
from ..utils.copy_fields import copy_fields from ..types.mutation import Mutation, MutationMeta
from ..utils.props import props
from ..types.objecttype import ObjectType from ..types.objecttype import ObjectType
from ..utils.is_base_type import is_base_type
from ..types.options import Options from ..types.options import Options
from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from ..utils.props import props
class ClientIDMutationMeta(MutationMeta): class ClientIDMutationMeta(MutationMeta):
@ -41,7 +40,8 @@ class ClientIDMutationMeta(MutationMeta):
output_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases)) output_fields = copy_fields(Field, get_fields(ObjectType, attrs, bases))
mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None) mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None)
assert mutate_and_get_payload, "{}.mutate_and_get_payload method is required in a ClientIDMutation ObjectType.".format(cls.__name__) assert mutate_and_get_payload, "{}.mutate_and_get_payload method is required in a ClientIDMutation ObjectType.".format(
cls.__name__)
field = mutation_with_client_mutation_id( field = mutation_with_client_mutation_id(
name=options.name or cls.__name__, name=options.name or cls.__name__,
@ -55,5 +55,6 @@ class ClientIDMutationMeta(MutationMeta):
class ClientIDMutation(six.with_metaclass(ClientIDMutationMeta, Mutation)): class ClientIDMutation(six.with_metaclass(ClientIDMutationMeta, Mutation)):
class Meta: class Meta:
abstract = True abstract = True

View File

@ -1,11 +1,13 @@
from functools import partial from functools import partial
import six import six
from graphql_relay import node_definitions, from_global_id, to_global_id
from graphql_relay import from_global_id, node_definitions, to_global_id
from ..types.field import Field from ..types.field import Field
from ..types.options import Options
from ..types.objecttype import ObjectTypeMeta
from ..types.interface import Interface from ..types.interface import Interface
from ..types.objecttype import ObjectTypeMeta
from ..types.options import Options
class NodeMeta(ObjectTypeMeta): class NodeMeta(ObjectTypeMeta):
@ -22,7 +24,12 @@ class NodeMeta(ObjectTypeMeta):
id_resolver=id_resolver, id_resolver=id_resolver,
) )
cls._meta = Options(None, graphql_type=node_interface) cls._meta = Options(None, graphql_type=node_interface)
cls.Field = partial(Field.copy_and_extend, node_field, type=node_field.type, parent=cls, _creation_counter=None) cls.Field = partial(
Field.copy_and_extend,
node_field,
type=node_field.type,
parent=cls,
_creation_counter=None)
else: else:
# The interface provided by node_definitions is not an instance # The interface provided by node_definitions is not an instance
# of GrapheneInterfaceType, so it will have no graphql_type, # of GrapheneInterfaceType, so it will have no graphql_type,
@ -71,6 +78,8 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
in it in it
''' '''
if cls.require_get_node(): if cls.require_get_node():
assert hasattr(object_type, 'get_node'), '{}.get_node method is required by the Node interface.'.format(object_type.__name__) assert hasattr(
object_type, 'get_node'), '{}.get_node method is required by the Node interface.'.format(
object_type.__name__)
return super(Node, cls).implements(object_type) return super(Node, cls).implements(object_type)

View File

@ -1,10 +1,9 @@
import pytest
from ...types import ObjectType, Schema
from ...types.field import Field
from ...types.scalars import String
from ..connection import Connection from ..connection import Connection
from ..node import Node from ..node import Node
from ...types import ObjectType, Schema
from ...types.scalars import String
from ...types.field import Field
class MyObject(Node, ObjectType): class MyObject(Node, ObjectType):
@ -16,6 +15,7 @@ class MyObject(Node, ObjectType):
class MyObjectConnection(Connection): class MyObjectConnection(Connection):
class Meta: class Meta:
node = MyObject node = MyObject

View File

@ -1,13 +1,12 @@
import pytest import pytest
from graphql_relay import to_global_id from ...types import ObjectType, Schema
from ..mutation import ClientIDMutation
from ...types import ObjectType, Schema, implements
from ...types.scalars import String from ...types.scalars import String
from ..mutation import ClientIDMutation
class SaySomething(ClientIDMutation): class SaySomething(ClientIDMutation):
class Input: class Input:
what = String() what = String()
phrase = String() phrase = String()
@ -33,7 +32,8 @@ def test_no_mutate_and_get_payload():
class MyMutation(ClientIDMutation): class MyMutation(ClientIDMutation):
pass pass
assert "MyMutation.mutate_and_get_payload method is required in a ClientIDMutation ObjectType." == str(excinfo.value) assert "MyMutation.mutate_and_get_payload method is required in a ClientIDMutation ObjectType." == str(
excinfo.value)
def test_node_good(): def test_node_good():
@ -81,4 +81,4 @@ def test_node_query():
# first: String # first: String
# node(id: ID!): Node # node(id: ID!): Node
# } # }
# """.lstrip() # """.lstrip()

View File

@ -2,9 +2,9 @@ import pytest
from graphql_relay import to_global_id from graphql_relay import to_global_id
from ..node import Node from ...types import ObjectType, Schema
from ...types import ObjectType, Schema, implements
from ...types.scalars import String from ...types.scalars import String
from ..node import Node
class MyNode(Node, ObjectType): class MyNode(Node, ObjectType):
@ -59,6 +59,7 @@ def test_node_query_incorrect_id():
assert not executed.errors assert not executed.errors
assert executed.data == {'node': None} assert executed.data == {'node': None}
def test_str_schema(): def test_str_schema():
assert str(schema) == """ assert str(schema) == """
schema { schema {
@ -78,4 +79,4 @@ type RootQuery {
first: String first: String
node(id: ID!): Node node(id: ID!): Node
} }
""".lstrip() """.lstrip()

View File

@ -1,11 +1,12 @@
from graphql import graphql from graphql import graphql
from ...types import ObjectType, Schema
from ...types.scalars import Int, String
from ..node import Node from ..node import Node
from ...types import ObjectType, Schema, implements
from ...types.scalars import String, Int
class CustomNode(Node): class CustomNode(Node):
@staticmethod @staticmethod
def to_global_id(type, id): def to_global_id(type, id):
return id return id
@ -222,20 +223,20 @@ def test_have_correct_node_interface():
''' '''
expected = { expected = {
'__type': { '__type': {
'name': 'Node', 'name': 'Node',
'kind': 'INTERFACE', 'kind': 'INTERFACE',
'fields': [ 'fields': [
{ {
'name': 'id', 'name': 'id',
'type': { 'type': {
'kind': 'NON_NULL', 'kind': 'NON_NULL',
'ofType': { 'ofType': {
'name': 'ID', 'name': 'ID',
'kind': 'SCALAR' 'kind': 'SCALAR'
}
}
} }
} ]
}
]
} }
} }
result = graphql(schema, query) result = graphql(schema, query)
@ -271,29 +272,29 @@ def test_has_correct_node_root_field():
''' '''
expected = { expected = {
'__schema': { '__schema': {
'queryType': { 'queryType': {
'fields': [ 'fields': [
{ {
'name': 'node', 'name': 'node',
'type': { 'type': {
'name': 'Node', 'name': 'Node',
'kind': 'INTERFACE' 'kind': 'INTERFACE'
}, },
'args': [ 'args': [
{ {
'name': 'id', 'name': 'id',
'type': { 'type': {
'kind': 'NON_NULL', 'kind': 'NON_NULL',
'ofType': { 'ofType': {
'name': 'ID', 'name': 'ID',
'kind': 'SCALAR' 'kind': 'SCALAR'
} }
}
}
]
} }
}
] ]
} }
]
}
} }
} }
result = graphql(schema, query) result = graphql(schema, query)

View File

@ -8,4 +8,21 @@ from .field import Field, InputField
from .argument import Argument from .argument import Argument
from .inputobjecttype import InputObjectType from .inputobjecttype import InputObjectType
__all__ = ['ObjectType', 'InputObjectType', 'Interface', 'implements', 'Enum', 'Field', 'InputField', 'Schema', 'Scalar', 'String', 'ID', 'Int', 'Float', 'Boolean', 'List', 'NonNull', 'Argument'] __all__ = [
'ObjectType',
'InputObjectType',
'Interface',
'implements',
'Enum',
'Field',
'InputField',
'Schema',
'Scalar',
'String',
'ID',
'Int',
'Float',
'Boolean',
'List',
'NonNull',
'Argument']

View File

@ -1,6 +1,6 @@
import copy import copy
from collections import OrderedDict
import inspect import inspect
from collections import OrderedDict
from itertools import chain from itertools import chain
from graphql import GraphQLArgument from graphql import GraphQLArgument

View File

@ -1,4 +1,5 @@
class GrapheneGraphQLType(object): class GrapheneGraphQLType(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.graphene_type = kwargs.pop('graphene_type') self.graphene_type = kwargs.pop('graphene_type')
super(GrapheneGraphQLType, self).__init__(*args, **kwargs) super(GrapheneGraphQLType, self).__init__(*args, **kwargs)

View File

@ -1,16 +1,19 @@
import six
from graphql.type import GraphQLEnumType, GraphQLEnumValue
from collections import OrderedDict from collections import OrderedDict
import six
from graphql.type import GraphQLEnumType, GraphQLEnumValue
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType from .definitions import GrapheneGraphQLType
from .options import Options from .options import Options
from ..utils.is_base_type import is_base_type from .unmountedtype import UnmountedType
try: try:
from enum import Enum as PyEnum from enum import Enum as PyEnum
except ImportError: except ImportError:
from ..utils.enum import Enum as PyEnum from ..utils.enum import Enum as PyEnum
from .unmountedtype import UnmountedType
class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType): class GrapheneEnumType(GrapheneGraphQLType, GraphQLEnumType):
@ -65,6 +68,7 @@ class EnumTypeMeta(type):
class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)): class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)):
@classmethod @classmethod
def from_enum(cls, python_enum): def from_enum(cls, python_enum):
class Meta: class Meta:

View File

@ -9,6 +9,7 @@ from .argument import to_arguments
class AbstractField(object): class AbstractField(object):
@property @property
def name(self): def name(self):
return self._name or self.attname and to_camel_case(self.attname) return self._name or self.attname and to_camel_case(self.attname)
@ -39,7 +40,8 @@ class AbstractField(object):
class Field(AbstractField, GraphQLField, OrderedType): class Field(AbstractField, GraphQLField, OrderedType):
def __init__(self, type, args=None, resolver=None, source=None, deprecation_reason=None, name=None, description=None, required=False, _creation_counter=None, **extra_args): def __init__(self, type, args=None, resolver=None, source=None, deprecation_reason=None,
name=None, description=None, required=False, _creation_counter=None, **extra_args):
self.name = name self.name = name
self.attname = None self.attname = None
self.parent = None self.parent = None
@ -74,8 +76,7 @@ class Field(AbstractField, GraphQLField, OrderedType):
@property @property
def resolver(self): def resolver(self):
from .objecttype import ObjectType pass
from .interface import GrapheneInterfaceType
resolver = getattr(self.parent, 'resolve_{}'.format(self.attname), None) resolver = getattr(self.parent, 'resolve_{}'.format(self.attname), None)
@ -105,7 +106,7 @@ class Field(AbstractField, GraphQLField, OrderedType):
# root = self.parent() # root = self.parent()
# return resolver(root, *args, **kwargs) # return resolver(root, *args, **kwargs)
return self._resolver or resolver # resolver_wrapper return self._resolver or resolver # resolver_wrapper
@resolver.setter @resolver.setter
def resolver(self, resolver): def resolver(self, resolver):
@ -115,7 +116,9 @@ class Field(AbstractField, GraphQLField, OrderedType):
return self.copy_and_extend(self) return self.copy_and_extend(self)
@classmethod @classmethod
def copy_and_extend(cls, field, type=None, args=None, resolver=None, source=None, deprecation_reason=None, name=None, description=None, required=False, _creation_counter=False, parent=None, attname=None, **extra_args): def copy_and_extend(
cls, field, type=None, args=None, resolver=None, source=None, deprecation_reason=None, name=None,
description=None, required=False, _creation_counter=False, parent=None, attname=None, **extra_args):
if isinstance(field, Field): if isinstance(field, Field):
type = type or field._type type = type or field._type
resolver = resolver or field._resolver resolver = resolver or field._resolver
@ -185,7 +188,8 @@ class InputField(AbstractField, GraphQLInputObjectField, OrderedType):
return self.copy_and_extend(self) return self.copy_and_extend(self)
@classmethod @classmethod
def copy_and_extend(cls, field, type=None, default_value=None, description=None, name=None, required=False, parent=None, attname=None, _creation_counter=False): def copy_and_extend(cls, field, type=None, default_value=None, description=None, name=None,
required=False, parent=None, attname=None, _creation_counter=False):
if isinstance(field, Field): if isinstance(field, Field):
type = type or field._type type = type or field._type
name = name or field._name name = name or field._name

View File

@ -2,14 +2,14 @@ import six
from graphql import GraphQLInputObjectType from graphql import GraphQLInputObjectType
from .definitions import GrapheneGraphQLType
from .interface import attrs_without_fields
from .unmountedtype import UnmountedType
from .options import Options
from ..utils.is_base_type import is_base_type
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .field import InputField from .field import InputField
from .interface import attrs_without_fields
from .options import Options
from .unmountedtype import UnmountedType
class GrapheneInputObjectType(GrapheneGraphQLType, GraphQLInputObjectType): class GrapheneInputObjectType(GrapheneGraphQLType, GraphQLInputObjectType):

View File

@ -1,12 +1,13 @@
import six import six
from graphql import GraphQLInterfaceType from graphql import GraphQLInterfaceType
from .definitions import GrapheneGraphQLType
from .options import Options
from ..utils.is_base_type import is_base_type
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .field import Field from .field import Field
from .options import Options
class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType): class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType):
@ -72,4 +73,3 @@ class Interface(six.with_metaclass(InterfaceTypeMeta)):
For example, if we want to check that the ObjectType have some required things For example, if we want to check that the ObjectType have some required things
in it like Node.get_node in it like Node.get_node
''' '''
pass

View File

@ -1,11 +1,11 @@
from functools import partial from functools import partial
import six import six
from .objecttype import ObjectTypeMeta, ObjectType
from .field import Field
from ..utils.props import props
from ..utils.is_base_type import is_base_type from ..utils.is_base_type import is_base_type
from ..utils.props import props
from .field import Field
from .objecttype import ObjectType, ObjectTypeMeta
class MutationMeta(ObjectTypeMeta): class MutationMeta(ObjectTypeMeta):

View File

@ -1,15 +1,17 @@
import copy import copy
import six import six
from graphql import GraphQLObjectType from graphql import GraphQLObjectType
from .definitions import GrapheneGraphQLType
from .interface import GrapheneInterfaceType, InterfaceTypeMeta, Interface, attrs_without_fields
from .options import Options
from ..utils.is_base_type import is_base_type
from ..utils.get_fields import get_fields
from ..utils.copy_fields import copy_fields from ..utils.copy_fields import copy_fields
from ..utils.get_fields import get_fields
from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .field import Field from .field import Field
from .interface import (GrapheneInterfaceType, Interface, InterfaceTypeMeta,
attrs_without_fields)
from .options import Options
class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType): class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType):
@ -120,6 +122,7 @@ def implements(*interfaces):
class ObjectType(six.with_metaclass(ObjectTypeMeta)): class ObjectType(six.with_metaclass(ObjectTypeMeta)):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# GraphQL ObjectType acting as container # GraphQL ObjectType acting as container
args_len = len(args) args_len = len(args)

View File

@ -1,10 +1,12 @@
import six import six
from graphql import GraphQLScalarType, GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean, GraphQLID
from .definitions import GrapheneGraphQLType from graphql import (GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt,
from .unmountedtype import UnmountedType GraphQLScalarType, GraphQLString)
from .options import Options
from ..utils.is_base_type import is_base_type from ..utils.is_base_type import is_base_type
from .definitions import GrapheneGraphQLType
from .options import Options
from .unmountedtype import UnmountedType
class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType): class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType):
@ -53,7 +55,7 @@ def construct_scalar_class(graphql_type):
# class String(Scalar): # class String(Scalar):
# class Meta: # class Meta:
# graphql_type = graphql_type # graphql_type = graphql_type
Meta = type('Meta', (object,), {'graphql_type':graphql_type}) Meta = type('Meta', (object,), {'graphql_type': graphql_type})
return type(graphql_type.name, (Scalar, ), {'Meta': Meta}) return type(graphql_type.name, (Scalar, ), {'Meta': Meta})

View File

@ -1,9 +1,12 @@
from graphql import graphql, GraphQLSchema from graphql import GraphQLSchema, graphql
from graphql.utils.introspection_query import introspection_query from graphql.utils.introspection_query import introspection_query
from graphql.utils.schema_printer import print_schema from graphql.utils.schema_printer import print_schema
# from graphql.type.schema import assert_object_implements_interface
from ..utils.get_graphql_type import get_graphql_type from ..utils.get_graphql_type import get_graphql_type
# from graphql.type.schema import assert_object_implements_interface
# from collections import defaultdict # from collections import defaultdict

View File

@ -6,6 +6,7 @@ from .unmountedtype import UnmountedType
class Structure(UnmountedType): class Structure(UnmountedType):
def __init__(self, of_type, *args, **kwargs): def __init__(self, of_type, *args, **kwargs):
super(Structure, self).__init__(*args, **kwargs) super(Structure, self).__init__(*args, **kwargs)
self.of_type = of_type self.of_type = of_type

View File

@ -1,7 +1,8 @@
import pytest
import copy import copy
from graphql import GraphQLString, GraphQLArgument import pytest
from graphql import GraphQLArgument, GraphQLString
from ..argument import Argument, to_arguments from ..argument import Argument, to_arguments
from ..scalars import String from ..scalars import String

View File

@ -1,9 +1,9 @@
from graphql.type import GraphQLEnumType, GraphQLEnumValue from graphql.type import GraphQLEnumType, GraphQLEnumValue
from ...utils.enum import Enum as PyEnum
from ..argument import Argument
from ..enum import Enum from ..enum import Enum
from ..field import Field from ..field import Field
from ..argument import Argument
from ...utils.enum import Enum as PyEnum
def test_enum_construction(): def test_enum_construction():

View File

@ -1,12 +1,12 @@
import pytest
import copy import copy
from graphql import GraphQLString, GraphQLField, GraphQLInt, GraphQLNonNull import pytest
from graphql import GraphQLField, GraphQLInt, GraphQLNonNull, GraphQLString
from ..field import Field
from ..argument import Argument from ..argument import Argument
from ..objecttype import ObjectType from ..field import Field
from ..scalars import String, Int from ..scalars import Int, String
def test_field(): def test_field():
@ -33,7 +33,7 @@ def test_field_wrong_name():
def test_not_source_and_resolver(): def test_not_source_and_resolver():
with pytest.raises(AssertionError) as excinfo: with pytest.raises(AssertionError) as excinfo:
Field(GraphQLString, source="a", resolver=lambda *_:None) Field(GraphQLString, source="a", resolver=lambda *_: None)
assert "You cannot have a source and a resolver at the same time" == str(excinfo.value) assert "You cannot have a source and a resolver at the same time" == str(excinfo.value)

View File

@ -1,17 +1,14 @@
import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInputObjectType from graphql import GraphQLInputObjectType, GraphQLString
from ..objecttype import ObjectType from ..field import InputField
from ..inputobjecttype import InputObjectType from ..inputobjecttype import InputObjectType
from ..field import Field, InputField
from ..scalars import String from ..scalars import String
def test_generate_inputobjecttype(): def test_generate_inputobjecttype():
class MyObjectType(InputObjectType): class MyObjectType(InputObjectType):
'''Documentation''' '''Documentation'''
pass
graphql_type = MyObjectType._meta.graphql_type graphql_type = MyObjectType._meta.graphql_type
assert isinstance(graphql_type, GraphQLInputObjectType) assert isinstance(graphql_type, GraphQLInputObjectType)
@ -21,6 +18,7 @@ def test_generate_inputobjecttype():
def test_generate_inputobjecttype_with_meta(): def test_generate_inputobjecttype_with_meta():
class MyObjectType(InputObjectType): class MyObjectType(InputObjectType):
class Meta: class Meta:
name = 'MyOtherObjectType' name = 'MyOtherObjectType'
description = 'Documentation' description = 'Documentation'

View File

@ -1,15 +1,14 @@
import pytest import pytest
from graphql import GraphQLInterfaceType, GraphQLField, GraphQLString, GraphQLInterfaceType from graphql import GraphQLField, GraphQLInterfaceType, GraphQLString
from ..interface import Interface
from ..field import Field from ..field import Field
from ..interface import Interface
def test_generate_interface(): def test_generate_interface():
class MyInterface(Interface): class MyInterface(Interface):
'''Documentation''' '''Documentation'''
pass
graphql_type = MyInterface._meta.graphql_type graphql_type = MyInterface._meta.graphql_type
assert isinstance(graphql_type, GraphQLInterfaceType) assert isinstance(graphql_type, GraphQLInterfaceType)
@ -19,6 +18,7 @@ def test_generate_interface():
def test_generate_interface_with_meta(): def test_generate_interface_with_meta():
class MyInterface(Interface): class MyInterface(Interface):
class Meta: class Meta:
name = 'MyOtherInterface' name = 'MyOtherInterface'
description = 'Documentation' description = 'Documentation'

View File

@ -1,14 +1,11 @@
import pytest import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType from graphql import GraphQLObjectType, GraphQLString
from ..schema import Schema
from ..objecttype import ObjectType
from ..mutation import Mutation
from ..interface import Interface
from ..scalars import String
from ..field import Field from ..field import Field
from ..argument import Argument from ..mutation import Mutation
from ..objecttype import ObjectType
from ..scalars import String
def test_generate_mutation_no_args(): def test_generate_mutation_no_args():
@ -48,6 +45,7 @@ def test_generate_mutation_with_args():
def test_generate_mutation_with_meta(): def test_generate_mutation_with_meta():
class MyMutation(Mutation): class MyMutation(Mutation):
class Meta: class Meta:
name = 'MyOtherMutation' name = 'MyOtherMutation'
description = 'Documentation' description = 'Documentation'
@ -64,6 +62,7 @@ def test_generate_mutation_with_meta():
def test_empty_mutation_has_meta(): def test_empty_mutation_has_meta():
class MyMutation(Mutation): class MyMutation(Mutation):
@classmethod @classmethod
def mutate(cls, *args, **kwargs): def mutate(cls, *args, **kwargs):
pass pass

View File

@ -1,12 +1,11 @@
import pytest import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType from graphql import (GraphQLField, GraphQLInterfaceType, GraphQLObjectType,
GraphQLString)
from ..schema import Schema
from ..objecttype import ObjectType
from ..interface import Interface
from ..scalars import String
from ..field import Field from ..field import Field
from ..interface import Interface
from ..objecttype import ObjectType
class Container(ObjectType): class Container(ObjectType):
@ -17,7 +16,6 @@ class Container(ObjectType):
def test_generate_objecttype(): def test_generate_objecttype():
class MyObjectType(ObjectType): class MyObjectType(ObjectType):
'''Documentation''' '''Documentation'''
pass
graphql_type = MyObjectType._meta.graphql_type graphql_type = MyObjectType._meta.graphql_type
assert isinstance(graphql_type, GraphQLObjectType) assert isinstance(graphql_type, GraphQLObjectType)
@ -27,6 +25,7 @@ def test_generate_objecttype():
def test_generate_objecttype_with_meta(): def test_generate_objecttype_with_meta():
class MyObjectType(ObjectType): class MyObjectType(ObjectType):
class Meta: class Meta:
name = 'MyOtherObjectType' name = 'MyOtherObjectType'
description = 'Documentation' description = 'Documentation'
@ -139,6 +138,7 @@ def test_objecttype_reuse_graphql_type():
}) })
class GrapheneObjectType(ObjectType): class GrapheneObjectType(ObjectType):
class Meta: class Meta:
graphql_type = MyGraphQLType graphql_type = MyGraphQLType
@ -169,6 +169,7 @@ def test_objecttype_graphql_interface():
}) })
class GrapheneObjectType(ObjectType): class GrapheneObjectType(ObjectType):
class Meta: class Meta:
interfaces = [MyInterface] interfaces = [MyInterface]
@ -185,6 +186,7 @@ def test_objecttype_graphene_interface():
extended = Field(GraphQLString) extended = Field(GraphQLString)
class GrapheneObjectType(ObjectType): class GrapheneObjectType(ObjectType):
class Meta: class Meta:
interfaces = [GrapheneInterface] interfaces = [GrapheneInterface]

View File

@ -1,13 +1,15 @@
import pytest import pytest
from ..scalars import Scalar, String, Int, Float, Boolean
from graphene.utils.get_graphql_type import get_graphql_type
from graphql import GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString
from ..field import Field from ..field import Field
from ..objecttype import ObjectType from ..objecttype import ObjectType
from ..scalars import Boolean, Float, Int, Scalar, String
from graphql import GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean
from graphene.utils.get_graphql_type import get_graphql_type
class DatetimeScalar(Scalar): class DatetimeScalar(Scalar):
def serialize(value): def serialize(value):
return value.isoformat() return value.isoformat()

View File

@ -1,9 +1,9 @@
from ..scalars import String
from ..field import Field from ..field import Field
from ..objecttype import ObjectType
from ..interface import Interface from ..interface import Interface
from ..structures import List from ..objecttype import ObjectType
from ..scalars import String
from ..schema import Schema from ..schema import Schema
from ..structures import List
class Character(Interface): class Character(Interface):
@ -18,6 +18,7 @@ class Pet(ObjectType):
# @implements(Character) # @implements(Character)
class Human(ObjectType): class Human(ObjectType):
class Meta: class Meta:
interfaces = [Character] interfaces = [Character]
@ -44,9 +45,11 @@ schema = Schema(query=RootQuery, types=[Human])
def test_schema(): def test_schema():
executed = schema.execute('{ character {name, bestFriend { name }, friends { name}, ...on Human {pet { type } } } }') executed = schema.execute(
'{ character {name, bestFriend { name }, friends { name}, ...on Human {pet { type } } } }')
assert not executed.errors assert not executed.errors
assert executed.data == {'character': {'name': 'Harry', 'bestFriend': {'name': 'Best'}, 'friends': [{'name': 'Peter'}], 'pet': {'type': 'Dog'}}} assert executed.data == {'character': {'name': 'Harry', 'bestFriend': {
'name': 'Best'}, 'friends': [{'name': 'Peter'}], 'pet': {'type': 'Dog'}}}
def test_schema_introspect(): def test_schema_introspect():

View File

@ -1,10 +1,9 @@
import pytest
from graphql import GraphQLString, GraphQLList, GraphQLNonNull from graphql import GraphQLList, GraphQLNonNull, GraphQLString
from ..structures import List, NonNull
from ..scalars import String
from ..field import Field from ..field import Field
from ..scalars import String
from ..structures import List, NonNull
def test_list(): def test_list():

View File

@ -1,6 +1,6 @@
from .field import Field, InputField
from .argument import Argument
from ..utils.orderedtype import OrderedType from ..utils.orderedtype import OrderedType
from .argument import Argument
from .field import Field, InputField
# UnmountedType ? # UnmountedType ?

View File

@ -1,5 +1,4 @@
from collections import OrderedDict from collections import OrderedDict
from ..types.field import Field, InputField
def copy_fields(like, fields, **extra): def copy_fields(like, fields, **extra):

View File

@ -35,6 +35,7 @@ except NameError:
# In Python 3 unicode no longer exists (it's just str) # In Python 3 unicode no longer exists (it's just str)
unicode = str unicode = str
class _RouteClassAttributeToGetattr(object): class _RouteClassAttributeToGetattr(object):
"""Route attribute access on a class to __getattr__. """Route attribute access on a class to __getattr__.
@ -44,6 +45,7 @@ class _RouteClassAttributeToGetattr(object):
class's __getattr__ method; this is done by raising AttributeError. class's __getattr__ method; this is done by raising AttributeError.
""" """
def __init__(self, fget=None): def __init__(self, fget=None):
self.fget = fget self.fget = fget
@ -62,9 +64,9 @@ class _RouteClassAttributeToGetattr(object):
def _is_descriptor(obj): def _is_descriptor(obj):
"""Returns True if obj is a descriptor, False otherwise.""" """Returns True if obj is a descriptor, False otherwise."""
return ( return (
hasattr(obj, '__get__') or hasattr(obj, '__get__') or
hasattr(obj, '__set__') or hasattr(obj, '__set__') or
hasattr(obj, '__delete__')) hasattr(obj, '__delete__'))
def _is_dunder(name): def _is_dunder(name):
@ -85,6 +87,7 @@ def _is_sunder(name):
def _make_class_unpicklable(cls): def _make_class_unpicklable(cls):
"""Make the given class un-picklable.""" """Make the given class un-picklable."""
def _break_on_call_reduce(self, protocol=None): def _break_on_call_reduce(self, protocol=None):
raise TypeError('%r cannot be pickled' % self) raise TypeError('%r cannot be pickled' % self)
cls.__reduce_ex__ = _break_on_call_reduce cls.__reduce_ex__ = _break_on_call_reduce
@ -98,6 +101,7 @@ class _EnumDict(dict):
enumeration member names. enumeration member names.
""" """
def __init__(self): def __init__(self):
super(_EnumDict, self).__init__() super(_EnumDict, self).__init__()
self._member_names = [] self._member_names = []
@ -155,7 +159,7 @@ class EnumMeta(type):
# cannot be mixed with other types (int, float, etc.) if it has an # cannot be mixed with other types (int, float, etc.) if it has an
# inherited __new__ unless a new __new__ is defined (or the resulting # inherited __new__ unless a new __new__ is defined (or the resulting
# class will fail). # class will fail).
if type(classdict) is dict: if isinstance(classdict, dict):
original_dict = classdict original_dict = classdict
classdict = _EnumDict() classdict = _EnumDict()
for k, v in original_dict.items(): for k, v in original_dict.items():
@ -163,7 +167,7 @@ class EnumMeta(type):
member_type, first_enum = metacls._get_mixins_(bases) member_type, first_enum = metacls._get_mixins_(bases)
__new__, save_new, use_args = metacls._find_new_(classdict, member_type, __new__, save_new, use_args = metacls._find_new_(classdict, member_type,
first_enum) first_enum)
# save enum items into separate mapping so they don't get baked into # save enum items into separate mapping so they don't get baked into
# the new class # the new class
members = dict((k, classdict[k]) for k in classdict._member_names) members = dict((k, classdict[k]) for k in classdict._member_names)
@ -257,7 +261,6 @@ class EnumMeta(type):
except TypeError: except TypeError:
pass pass
# If a custom type is mixed into the Enum, and it does not know how # If a custom type is mixed into the Enum, and it does not know how
# to pickle itself, pickle.dumps will succeed but pickle.loads will # to pickle itself, pickle.dumps will succeed but pickle.loads will
# fail. Rather than have the error show up later and possibly far # fail. Rather than have the error show up later and possibly far
@ -272,17 +275,16 @@ class EnumMeta(type):
if '__reduce_ex__' not in classdict: if '__reduce_ex__' not in classdict:
if member_type is not object: if member_type is not object:
methods = ('__getnewargs_ex__', '__getnewargs__', methods = ('__getnewargs_ex__', '__getnewargs__',
'__reduce_ex__', '__reduce__') '__reduce_ex__', '__reduce__')
if not any(m in member_type.__dict__ for m in methods): if not any(m in member_type.__dict__ for m in methods):
_make_class_unpicklable(enum_class) _make_class_unpicklable(enum_class)
unpicklable = True unpicklable = True
# double check that repr and friends are not the mixin's or various # double check that repr and friends are not the mixin's or various
# things break (such as pickle) # things break (such as pickle)
for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'): for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
class_method = getattr(enum_class, name) class_method = getattr(enum_class, name)
obj_method = getattr(member_type, name, None) getattr(member_type, name, None)
enum_method = getattr(first_enum, name, None) enum_method = getattr(first_enum, name, None)
if name not in classdict and class_method is not enum_method: if name not in classdict and class_method is not enum_method:
if name == '__reduce_ex__' and unpicklable: if name == '__reduce_ex__' and unpicklable:
@ -308,7 +310,7 @@ class EnumMeta(type):
'__eq__', '__eq__',
'__ne__', '__ne__',
'__hash__', '__hash__',
): ):
setattr(enum_class, method, getattr(int, method)) setattr(enum_class, method, getattr(int, method))
# replace any other __new__ with our own (as long as Enum is not None, # replace any other __new__ with our own (as long as Enum is not None,
@ -356,7 +358,7 @@ class EnumMeta(type):
# (see issue19025). # (see issue19025).
if attr in cls._member_map_: if attr in cls._member_map_:
raise AttributeError( raise AttributeError(
"%s: cannot delete Enum member." % cls.__name__) "%s: cannot delete Enum member." % cls.__name__)
super(EnumMeta, cls).__delattr__(attr) super(EnumMeta, cls).__delattr__(attr)
def __dir__(self): def __dir__(self):
@ -450,7 +452,7 @@ class EnumMeta(type):
if isinstance(names, basestring): if isinstance(names, basestring):
names = names.replace(',', ' ').split() names = names.replace(',', ' ').split()
if isinstance(names, (tuple, list)) and isinstance(names[0], basestring): if isinstance(names, (tuple, list)) and isinstance(names[0], basestring):
names = [(e, i+start) for (i, e) in enumerate(names)] names = [(e, i + start) for (i, e) in enumerate(names)]
# Here, names is either an iterable of (name, value) or a mapping. # Here, names is either an iterable of (name, value) or a mapping.
item = None # in case names is empty item = None # in case names is empty
@ -491,20 +493,19 @@ class EnumMeta(type):
if not bases or Enum is None: if not bases or Enum is None:
return object, Enum return object, Enum
# double check that we are not subclassing a class with existing # double check that we are not subclassing a class with existing
# enumeration members; while we're at it, see if any other data # enumeration members; while we're at it, see if any other data
# type has been mixed in so we can use the correct __new__ # type has been mixed in so we can use the correct __new__
member_type = first_enum = None member_type = first_enum = None
for base in bases: for base in bases:
if (base is not Enum and if (base is not Enum and
issubclass(base, Enum) and issubclass(base, Enum) and
base._member_names_): base._member_names_):
raise TypeError("Cannot extend enumerations") raise TypeError("Cannot extend enumerations")
# base is now the last base in bases # base is now the last base in bases
if not issubclass(base, Enum): if not issubclass(base, Enum):
raise TypeError("new enumerations must be created as " raise TypeError("new enumerations must be created as "
"`ClassName([mixin_type,] enum_type)`") "`ClassName([mixin_type,] enum_type)`")
# get correct mix-in type (either mix-in type of Enum subclass, or # get correct mix-in type (either mix-in type of Enum subclass, or
# first base if last base is Enum) # first base if last base is Enum)
@ -562,7 +563,7 @@ class EnumMeta(type):
N__new__, N__new__,
O__new__, O__new__,
E__new__, E__new__,
]: ]:
if method == '__member_new__': if method == '__member_new__':
classdict['__new__'] = target classdict['__new__'] = target
return None, False, True return None, False, True
@ -613,7 +614,7 @@ class EnumMeta(type):
None.__new__, None.__new__,
object.__new__, object.__new__,
Enum.__new__, Enum.__new__,
): ):
__new__ = target __new__ = target
break break
if __new__ is not None: if __new__ is not None:
@ -641,14 +642,15 @@ class EnumMeta(type):
temp_enum_dict = {} temp_enum_dict = {}
temp_enum_dict['__doc__'] = "Generic enumeration.\n\n Derive from this class to define new enumerations.\n\n" temp_enum_dict['__doc__'] = "Generic enumeration.\n\n Derive from this class to define new enumerations.\n\n"
def __new__(cls, value): def __new__(cls, value):
# all enum instances are actually created during class construction # all enum instances are actually created during class construction
# without calling this method; this method is called by the metaclass' # without calling this method; this method is called by the metaclass'
# __call__ (i.e. Color(3) ), and by pickle # __call__ (i.e. Color(3) ), and by pickle
if type(value) is cls: if isinstance(value, cls):
# For lookups like Color(Color.red) # For lookups like Color(Color.red)
value = value.value value = value.value
#return value # return value
# by-value search for a matching enum member # by-value search for a matching enum member
# see if it's in the reverse mapping (for hashable values) # see if it's in the reverse mapping (for hashable values)
try: try:
@ -663,12 +665,14 @@ def __new__(cls, value):
temp_enum_dict['__new__'] = __new__ temp_enum_dict['__new__'] = __new__
del __new__ del __new__
def __repr__(self): def __repr__(self):
return "<%s.%s: %r>" % ( return "<%s.%s: %r>" % (
self.__class__.__name__, self._name_, self._value_) self.__class__.__name__, self._name_, self._value_)
temp_enum_dict['__repr__'] = __repr__ temp_enum_dict['__repr__'] = __repr__
del __repr__ del __repr__
def __str__(self): def __str__(self):
return "%s.%s" % (self.__class__.__name__, self._name_) return "%s.%s" % (self.__class__.__name__, self._name_)
temp_enum_dict['__str__'] = __str__ temp_enum_dict['__str__'] = __str__
@ -677,15 +681,16 @@ del __str__
if pyver >= 3.0: if pyver >= 3.0:
def __dir__(self): def __dir__(self):
added_behavior = [ added_behavior = [
m m
for cls in self.__class__.mro() for cls in self.__class__.mro()
for m in cls.__dict__ for m in cls.__dict__
if m[0] != '_' and m not in self._member_map_ if m[0] != '_' and m not in self._member_map_
] ]
return (['__class__', '__doc__', '__module__', ] + added_behavior) return (['__class__', '__doc__', '__module__', ] + added_behavior)
temp_enum_dict['__dir__'] = __dir__ temp_enum_dict['__dir__'] = __dir__
del __dir__ del __dir__
def __format__(self, format_spec): def __format__(self, format_spec):
# mixed-in Enums should use the mixed-in type's __format__, otherwise # mixed-in Enums should use the mixed-in type's __format__, otherwise
# we can get strange results with the Enum name showing up instead of # we can get strange results with the Enum name showing up instead of
@ -710,7 +715,7 @@ del __format__
if pyver < 2.6: if pyver < 2.6:
def __cmp__(self, other): def __cmp__(self, other):
if type(other) is self.__class__: if isinstance(other, self.__class__):
if self is other: if self is other:
return 0 return 0
return -1 return -1
@ -743,24 +748,27 @@ else:
def __eq__(self, other): def __eq__(self, other):
if type(other) is self.__class__: if isinstance(other, self.__class__):
return self is other return self is other
return NotImplemented return NotImplemented
temp_enum_dict['__eq__'] = __eq__ temp_enum_dict['__eq__'] = __eq__
del __eq__ del __eq__
def __ne__(self, other): def __ne__(self, other):
if type(other) is self.__class__: if isinstance(other, self.__class__):
return self is not other return self is not other
return NotImplemented return NotImplemented
temp_enum_dict['__ne__'] = __ne__ temp_enum_dict['__ne__'] = __ne__
del __ne__ del __ne__
def __hash__(self): def __hash__(self):
return hash(self._name_) return hash(self._name_)
temp_enum_dict['__hash__'] = __hash__ temp_enum_dict['__hash__'] = __hash__
del __hash__ del __hash__
def __reduce_ex__(self, proto): def __reduce_ex__(self, proto):
return self.__class__, (self._value_, ) return self.__class__, (self._value_, )
temp_enum_dict['__reduce_ex__'] = __reduce_ex__ temp_enum_dict['__reduce_ex__'] = __reduce_ex__
@ -773,18 +781,21 @@ del __reduce_ex__
# members are not set directly on the enum class -- __getattr__ is # members are not set directly on the enum class -- __getattr__ is
# used to look them up. # used to look them up.
@_RouteClassAttributeToGetattr @_RouteClassAttributeToGetattr
def name(self): def name(self):
return self._name_ return self._name_
temp_enum_dict['name'] = name temp_enum_dict['name'] = name
del name del name
@_RouteClassAttributeToGetattr @_RouteClassAttributeToGetattr
def value(self): def value(self):
return self._value_ return self._value_
temp_enum_dict['value'] = value temp_enum_dict['value'] = value
del value del value
@classmethod @classmethod
def _convert(cls, name, module, filter, source=None): def _convert(cls, name, module, filter, source=None):
""" """
@ -815,12 +826,15 @@ del temp_enum_dict
# Enum has now been created # Enum has now been created
########################### ###########################
class IntEnum(int, Enum): class IntEnum(int, Enum):
"""Enum where members are also (and must be) ints""" """Enum where members are also (and must be) ints"""
def _reduce_ex_by_name(self, proto): def _reduce_ex_by_name(self, proto):
return self.name return self.name
def unique(enumeration): def unique(enumeration):
"""Class decorator that ensures only unique members exist in an enumeration.""" """Class decorator that ensures only unique members exist in an enumeration."""
duplicates = [] duplicates = []
@ -829,9 +843,9 @@ def unique(enumeration):
duplicates.append((name, member.name)) duplicates.append((name, member.name))
if duplicates: if duplicates:
duplicate_names = ', '.join( duplicate_names = ', '.join(
["%s -> %s" % (alias, name) for (alias, name) in duplicates] ["%s -> %s" % (alias, name) for (alias, name) in duplicates]
) )
raise ValueError('duplicate names found in %r: %s' % raise ValueError('duplicate names found in %r: %s' %
(enumeration, duplicate_names) (enumeration, duplicate_names)
) )
return enumeration return enumeration

View File

@ -1,9 +1,9 @@
from collections import OrderedDict from collections import OrderedDict
from .get_graphql_type import get_graphql_type
from .is_graphene_type import is_graphene_type
from ..types.field import Field, InputField from ..types.field import Field, InputField
from ..types.unmountedtype import UnmountedType from ..types.unmountedtype import UnmountedType
from .get_graphql_type import get_graphql_type
from .is_graphene_type import is_graphene_type
def get_fields_from_attrs(in_type, attrs): def get_fields_from_attrs(in_type, attrs):

View File

@ -1,8 +1,10 @@
from collections import OrderedDict from collections import OrderedDict
from graphql import GraphQLField, GraphQLString, GraphQLInterfaceType, GraphQLInt, GraphQLFloat
from ..get_fields import get_fields_from_attrs, get_fields_from_types
from ...types import Field, String, Argument, ObjectType from graphql import (GraphQLField, GraphQLFloat, GraphQLInt,
GraphQLInterfaceType, GraphQLString)
from ...types import Argument, Field, ObjectType, String
from ..get_fields import get_fields_from_attrs, get_fields_from_types
def test_get_fields_from_attrs(): def test_get_fields_from_attrs():

View File

@ -1,11 +1,10 @@
import pytest import pytest
from graphql.type.definition import is_type
from graphql import GraphQLObjectType, GraphQLField, GraphQLString
from graphene.types import ObjectType from graphene.types import ObjectType
from ..get_graphql_type import get_graphql_type from graphql import GraphQLField, GraphQLObjectType, GraphQLString
from graphql.type.definition import is_type
from ..get_graphql_type import get_graphql_type
MyGraphQLType = GraphQLObjectType('MyGraphQLType', fields={ MyGraphQLType = GraphQLObjectType('MyGraphQLType', fields={
'field': GraphQLField(GraphQLString) 'field': GraphQLField(GraphQLString)
@ -21,6 +20,7 @@ def test_get_graphql_type_graphene():
def test_get_graphql_type_custom_graphene_type(): def test_get_graphql_type_custom_graphene_type():
class MyGrapheneType(ObjectType): class MyGrapheneType(ObjectType):
class Meta: class Meta:
graphql_type = MyGraphQLType graphql_type = MyGraphQLType

View File

@ -1,9 +1,8 @@
from graphql import GraphQLObjectType, GraphQLField, GraphQLString from graphene.types import ObjectType
from graphql import GraphQLField, GraphQLObjectType, GraphQLString
from ..is_graphene_type import is_graphene_type from ..is_graphene_type import is_graphene_type
from graphene.types import ObjectType
def test_is_graphene_type_objecttype(): def test_is_graphene_type_objecttype():
class MyObjectType(ObjectType): class MyObjectType(ObjectType):