mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-18 12:30:37 +03:00
Remove unused code. Add more tests
This commit is contained in:
parent
9548d6932c
commit
f4a8d53409
|
@ -3,7 +3,7 @@ from collections import OrderedDict
|
||||||
from graphene.utils import cached_property
|
from graphene.utils import cached_property
|
||||||
|
|
||||||
DEFAULT_NAMES = ('description', 'name', 'is_interface', 'is_mutation',
|
DEFAULT_NAMES = ('description', 'name', 'is_interface', 'is_mutation',
|
||||||
'type_name', 'interfaces', 'proxy')
|
'type_name', 'interfaces')
|
||||||
|
|
||||||
|
|
||||||
class Options(object):
|
class Options(object):
|
||||||
|
@ -13,7 +13,6 @@ class Options(object):
|
||||||
self.local_fields = []
|
self.local_fields = []
|
||||||
self.is_interface = False
|
self.is_interface = False
|
||||||
self.is_mutation = False
|
self.is_mutation = False
|
||||||
self.proxy = False
|
|
||||||
self.interfaces = []
|
self.interfaces = []
|
||||||
self.parents = []
|
self.parents = []
|
||||||
self.valid_attrs = DEFAULT_NAMES
|
self.valid_attrs = DEFAULT_NAMES
|
||||||
|
@ -55,8 +54,6 @@ class Options(object):
|
||||||
"'class Meta' got invalid attribute(s): %s" %
|
"'class Meta' got invalid attribute(s): %s" %
|
||||||
','.join(
|
','.join(
|
||||||
meta_attrs.keys()))
|
meta_attrs.keys()))
|
||||||
else:
|
|
||||||
self.proxy = False
|
|
||||||
|
|
||||||
del self.meta
|
del self.meta
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
from graphql.core.type.definition import GraphQLScalarType
|
|
||||||
|
|
||||||
|
|
||||||
def skip(value):
|
|
||||||
return None
|
|
||||||
|
|
||||||
GraphQLSkipField = GraphQLScalarType(name='SkipField',
|
|
||||||
serialize=skip,
|
|
||||||
parse_value=skip,
|
|
||||||
parse_literal=skip)
|
|
|
@ -1,9 +1,10 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from functools import wraps
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from graphql.core.type import GraphQLArgument
|
from graphql.core.type import GraphQLArgument
|
||||||
|
|
||||||
from ...utils import to_camel_case
|
from ...utils import to_camel_case, ProxySnakeDict
|
||||||
from .base import ArgumentType, BaseType, OrderedType
|
from .base import ArgumentType, BaseType, OrderedType
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,3 +70,11 @@ def to_arguments(*args, **kwargs):
|
||||||
arguments[argument.name] = argument
|
arguments[argument.name] = argument
|
||||||
|
|
||||||
return sorted(arguments.values())
|
return sorted(arguments.values())
|
||||||
|
|
||||||
|
|
||||||
|
def snake_case_args(resolver):
|
||||||
|
@wraps(resolver)
|
||||||
|
def wrapped_resolver(instance, args, info):
|
||||||
|
return resolver(instance, ProxySnakeDict(args), info)
|
||||||
|
|
||||||
|
return wrapped_resolver
|
||||||
|
|
|
@ -1,25 +1,16 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from functools import wraps
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from graphql.core.type import GraphQLField, GraphQLInputObjectField
|
from graphql.core.type import GraphQLField, GraphQLInputObjectField
|
||||||
|
|
||||||
from ...utils import ProxySnakeDict, to_camel_case
|
from ...utils import to_camel_case
|
||||||
from ..types import BaseObjectType, InputObjectType
|
from ..types import BaseObjectType, InputObjectType
|
||||||
from .argument import ArgumentsGroup
|
from .argument import ArgumentsGroup, snake_case_args
|
||||||
from .base import LazyType, MountType, OrderedType
|
from .base import LazyType, MountType, OrderedType
|
||||||
from .definitions import NonNull
|
from .definitions import NonNull
|
||||||
|
|
||||||
|
|
||||||
def make_args_snake_case(resolver):
|
|
||||||
@wraps(resolver)
|
|
||||||
def wrapped_resolver(instance, args, info):
|
|
||||||
return resolver(instance, ProxySnakeDict(args), info)
|
|
||||||
|
|
||||||
return wrapped_resolver
|
|
||||||
|
|
||||||
|
|
||||||
class Empty(object):
|
class Empty(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -91,7 +82,7 @@ class Field(OrderedType):
|
||||||
arguments = type_objecttype.get_arguments()
|
arguments = type_objecttype.get_arguments()
|
||||||
resolver = getattr(type_objecttype, 'mutate')
|
resolver = getattr(type_objecttype, 'mutate')
|
||||||
|
|
||||||
resolver = make_args_snake_case(resolver)
|
resolver = snake_case_args(resolver)
|
||||||
assert type, 'Internal type for field %s is None' % str(self)
|
assert type, 'Internal type for field %s is None' % str(self)
|
||||||
return GraphQLField(type, args=schema.T(arguments), resolver=resolver,
|
return GraphQLField(type, args=schema.T(arguments), resolver=resolver,
|
||||||
description=description,)
|
description=description,)
|
||||||
|
|
|
@ -168,20 +168,9 @@ class BaseObjectType(BaseType):
|
||||||
|
|
||||||
signals.post_init.send(self.__class__, instance=self)
|
signals.post_init.send(self.__class__, instance=self)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def fields_as_arguments(cls, schema):
|
|
||||||
return OrderedDict(
|
|
||||||
[(f.attname, GraphQLArgument(f.internal_type(schema)))
|
|
||||||
for f in cls._meta.fields])
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def resolve_objecttype(cls, schema, instance, *args):
|
|
||||||
return instance.__class__
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve_type(cls, schema, instance, *args):
|
def resolve_type(cls, schema, instance, *args):
|
||||||
objecttype = cls.resolve_objecttype(schema, instance, *args)
|
return schema.T(instance.__class__)
|
||||||
return schema.T(objecttype)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def internal_type(cls, schema):
|
def internal_type(cls, schema):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from graphene.core.schema import Schema
|
||||||
from graphene.core.types import ObjectType
|
from graphene.core.types import ObjectType
|
||||||
from graphql.core.type import GraphQLArgument
|
from graphql.core.type import GraphQLArgument
|
||||||
|
|
||||||
from ..argument import Argument, to_arguments
|
from ..argument import Argument, to_arguments, snake_case_args
|
||||||
from ..scalars import String
|
from ..scalars import String
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,3 +45,9 @@ def test_to_arguments_wrong_type():
|
||||||
p=3
|
p=3
|
||||||
)
|
)
|
||||||
assert 'Unknown argument p=3' == str(excinfo.value)
|
assert 'Unknown argument p=3' == str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_snake_case_args():
|
||||||
|
resolver = lambda instance, args, info: args['my_arg']['inner_arg']
|
||||||
|
r = snake_case_args(resolver)
|
||||||
|
assert r(None, {'myArg': {'innerArg': 3}}, None) == 3
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from collections import Iterable
|
from collections import Iterable
|
||||||
|
|
||||||
from graphene.core.fields import Field
|
from graphene.core.fields import Field
|
||||||
|
from graphene.core.types.definitions import NonNull
|
||||||
from graphene.core.types.scalars import ID, Int, String
|
from graphene.core.types.scalars import ID, Int, String
|
||||||
from graphql_relay.connection.arrayconnection import connection_from_list
|
from graphql_relay.connection.arrayconnection import connection_from_list
|
||||||
from graphql_relay.node.node import from_global_id
|
from graphql_relay.node.node import from_global_id
|
||||||
|
@ -67,6 +68,7 @@ class ConnectionField(Field):
|
||||||
|
|
||||||
|
|
||||||
class NodeField(Field):
|
class NodeField(Field):
|
||||||
|
'''Fetches an object given its ID'''
|
||||||
|
|
||||||
def __init__(self, object_type=None, *args, **kwargs):
|
def __init__(self, object_type=None, *args, **kwargs):
|
||||||
from graphene.relay.types import Node
|
from graphene.relay.types import Node
|
||||||
|
@ -96,8 +98,7 @@ class GlobalIDField(Field):
|
||||||
'''The ID of an object'''
|
'''The ID of an object'''
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(GlobalIDField, self).__init__(ID(), *args, **kwargs)
|
super(GlobalIDField, self).__init__(NonNull(ID()), *args, **kwargs)
|
||||||
self.required = True
|
|
||||||
|
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
from graphene.relay.utils import is_node, is_node_type
|
from graphene.relay.utils import is_node, is_node_type
|
||||||
|
|
|
@ -99,7 +99,7 @@ class BaseNode(object):
|
||||||
|
|
||||||
class Node(BaseNode, Interface):
|
class Node(BaseNode, Interface):
|
||||||
'''An object with an ID'''
|
'''An object with an ID'''
|
||||||
id = GlobalIDField(required=True)
|
id = GlobalIDField()
|
||||||
|
|
||||||
|
|
||||||
class MutationInputType(InputObjectType):
|
class MutationInputType(InputObjectType):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user