mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Fixed lint errors
This commit is contained in:
parent
7073208517
commit
a2ab008ead
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
autoflake ./ -r --remove-unused-variables --remove-all-unused-imports --in-place
|
autoflake ./ -r --remove-unused-variables --remove-all-unused-imports --in-place
|
||||||
autopep8 ./ -r --in-place
|
autopep8 ./ -r --in-place --experimental --aggressive --max-line-length 120
|
||||||
isort -rc .
|
isort -rc .
|
||||||
|
|
|
@ -40,7 +40,30 @@ from graphene.decorators import (
|
||||||
resolve_only_args
|
resolve_only_args
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = ['Enum', 'Argument', 'String', 'Int', 'Boolean', 'Float', 'ID', 'List', 'NonNull', 'signals', 'Schema',
|
__all__ = [
|
||||||
'BaseType', 'LazyType', 'ObjectType', 'Interface', 'Mutation', 'Field', 'InputField', 'StringField',
|
'Enum',
|
||||||
'IntField', 'BooleanField', 'IDField', 'ListField', 'NonNullField',
|
'Argument',
|
||||||
'FloatField', 'resolve_only_args']
|
'String',
|
||||||
|
'Int',
|
||||||
|
'Boolean',
|
||||||
|
'Float',
|
||||||
|
'ID',
|
||||||
|
'List',
|
||||||
|
'NonNull',
|
||||||
|
'signals',
|
||||||
|
'Schema',
|
||||||
|
'BaseType',
|
||||||
|
'LazyType',
|
||||||
|
'ObjectType',
|
||||||
|
'Interface',
|
||||||
|
'Mutation',
|
||||||
|
'Field',
|
||||||
|
'InputField',
|
||||||
|
'StringField',
|
||||||
|
'IntField',
|
||||||
|
'BooleanField',
|
||||||
|
'IDField',
|
||||||
|
'ListField',
|
||||||
|
'NonNullField',
|
||||||
|
'FloatField',
|
||||||
|
'resolve_only_args']
|
||||||
|
|
|
@ -16,7 +16,8 @@ except AttributeError:
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def convert_django_field(field):
|
def convert_django_field(field):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Don't know how to convert the Django field %s (%s)" % (field, field.__class__))
|
"Don't know how to convert the Django field %s (%s)" %
|
||||||
|
(field, field.__class__))
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(models.DateField)
|
@convert_django_field.register(models.DateField)
|
||||||
|
|
|
@ -32,6 +32,7 @@ class DjangoOptions(Options):
|
||||||
return
|
return
|
||||||
if not self.model:
|
if not self.model:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'Django ObjectType %s must have a model in the Meta class attr' % cls)
|
'Django ObjectType %s must have a model in the Meta class attr' %
|
||||||
|
cls)
|
||||||
elif not inspect.isclass(self.model) or not issubclass(self.model, models.Model):
|
elif not inspect.isclass(self.model) or not issubclass(self.model, models.Model):
|
||||||
raise Exception('Provided model in %s is not a Django model' % cls)
|
raise Exception('Provided model in %s is not a Django model' % cls)
|
||||||
|
|
|
@ -87,7 +87,8 @@ def test_should_node():
|
||||||
article = graphene.Field(ArticleNode)
|
article = graphene.Field(ArticleNode)
|
||||||
|
|
||||||
def resolve_reporter(self, *args, **kwargs):
|
def resolve_reporter(self, *args, **kwargs):
|
||||||
return ReporterNode(Reporter(id=1, first_name='ABA', last_name='X'))
|
return ReporterNode(
|
||||||
|
Reporter(id=1, first_name='ABA', last_name='X'))
|
||||||
|
|
||||||
query = '''
|
query = '''
|
||||||
query ReporterQuery {
|
query ReporterQuery {
|
||||||
|
|
|
@ -46,11 +46,13 @@ class InstanceObjectType(BaseObjectType):
|
||||||
return getattr(self.instance, attr)
|
return getattr(self.instance, attr)
|
||||||
|
|
||||||
|
|
||||||
class DjangoObjectType(six.with_metaclass(DjangoObjectTypeMeta, InstanceObjectType)):
|
class DjangoObjectType(six.with_metaclass(
|
||||||
|
DjangoObjectTypeMeta, InstanceObjectType)):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DjangoInterface(six.with_metaclass(DjangoObjectTypeMeta, InstanceObjectType)):
|
class DjangoInterface(six.with_metaclass(
|
||||||
|
DjangoObjectTypeMeta, InstanceObjectType)):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,14 @@ class GraphQLView(View):
|
||||||
errors = [{
|
errors = [{
|
||||||
"message": str(e)
|
"message": str(e)
|
||||||
} for e in errors]
|
} for e in errors]
|
||||||
return HttpResponse(json.dumps({'errors': errors}), content_type='application/json')
|
return HttpResponse(
|
||||||
|
json.dumps({'errors': errors}),
|
||||||
|
content_type='application/json')
|
||||||
|
|
||||||
def execute_query(self, request, query, *args, **kwargs):
|
def execute_query(self, request, query, *args, **kwargs):
|
||||||
if not query:
|
if not query:
|
||||||
return self.response_errors(Exception("Must provide query string."))
|
return self.response_errors(
|
||||||
|
Exception("Must provide query string."))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
result = self.schema.execute(query, *args, **kwargs)
|
result = self.schema.execute(query, *args, **kwargs)
|
||||||
|
@ -59,7 +62,8 @@ class GraphQLView(View):
|
||||||
received_json_data = json.loads(request.body.decode())
|
received_json_data = json.loads(request.body.decode())
|
||||||
query = received_json_data.get('query')
|
query = received_json_data.get('query')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return self.response_errors(ValueError("Malformed json body in the post data"))
|
return self.response_errors(ValueError(
|
||||||
|
"Malformed json body in the post data"))
|
||||||
else:
|
else:
|
||||||
query = request.POST.get('query') or request.GET.get('query')
|
query = request.POST.get('query') or request.GET.get('query')
|
||||||
return self.execute_query(request, query or '')
|
return self.execute_query(request, query or '')
|
||||||
|
|
|
@ -52,7 +52,9 @@ class Options(object):
|
||||||
# Any leftover attributes must be invalid.
|
# Any leftover attributes must be invalid.
|
||||||
if meta_attrs != {}:
|
if meta_attrs != {}:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()))
|
"'class Meta' got invalid attribute(s): %s" %
|
||||||
|
','.join(
|
||||||
|
meta_attrs.keys()))
|
||||||
else:
|
else:
|
||||||
self.proxy = False
|
self.proxy = False
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ class GraphQLSchema(_GraphQLSchema):
|
||||||
class Schema(object):
|
class Schema(object):
|
||||||
_executor = None
|
_executor = None
|
||||||
|
|
||||||
def __init__(self, query=None, mutation=None, name='Schema', executor=None):
|
def __init__(self, query=None, mutation=None,
|
||||||
|
name='Schema', executor=None):
|
||||||
self._types_names = {}
|
self._types_names = {}
|
||||||
self._types = {}
|
self._types = {}
|
||||||
self.mutation = mutation
|
self.mutation = mutation
|
||||||
|
@ -36,7 +37,9 @@ class Schema(object):
|
||||||
def T(self, object_type):
|
def T(self, object_type):
|
||||||
if not object_type:
|
if not object_type:
|
||||||
return
|
return
|
||||||
if inspect.isclass(object_type) and issubclass(object_type, BaseType) or isinstance(object_type, BaseType):
|
if inspect.isclass(object_type) and issubclass(
|
||||||
|
object_type, BaseType) or isinstance(
|
||||||
|
object_type, BaseType):
|
||||||
if object_type not in self._types:
|
if object_type not in self._types:
|
||||||
internal_type = object_type.internal_type(self)
|
internal_type = object_type.internal_type(self)
|
||||||
self._types[object_type] = internal_type
|
self._types[object_type] = internal_type
|
||||||
|
@ -63,7 +66,9 @@ class Schema(object):
|
||||||
def schema(self):
|
def schema(self):
|
||||||
if not self.query:
|
if not self.query:
|
||||||
raise Exception('You have to define a base query type')
|
raise Exception('You have to define a base query type')
|
||||||
return GraphQLSchema(self, query=self.T(self.query), mutation=self.T(self.mutation))
|
return GraphQLSchema(
|
||||||
|
self, query=self.T(self.query),
|
||||||
|
mutation=self.T(self.mutation))
|
||||||
|
|
||||||
def register(self, object_type):
|
def register(self, object_type):
|
||||||
type_name = object_type._meta.type_name
|
type_name = object_type._meta.type_name
|
||||||
|
@ -78,7 +83,8 @@ class Schema(object):
|
||||||
name = getattr(type, 'name', None)
|
name = getattr(type, 'name', None)
|
||||||
if name:
|
if name:
|
||||||
objecttype = self._types_names.get(name, None)
|
objecttype = self._types_names.get(name, None)
|
||||||
if objecttype and inspect.isclass(objecttype) and issubclass(objecttype, BaseObjectType):
|
if objecttype and inspect.isclass(
|
||||||
|
objecttype) and issubclass(objecttype, BaseObjectType):
|
||||||
return objecttype
|
return objecttype
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
@ -95,7 +101,8 @@ class Schema(object):
|
||||||
def types(self):
|
def types(self):
|
||||||
return self._types_names
|
return self._types_names
|
||||||
|
|
||||||
def execute(self, request='', root=None, vars=None, operation_name=None, **kwargs):
|
def execute(self, request='', root=None, vars=None,
|
||||||
|
operation_name=None, **kwargs):
|
||||||
root = root or object()
|
root = root or object()
|
||||||
return self.executor.execute(
|
return self.executor.execute(
|
||||||
self.schema,
|
self.schema,
|
||||||
|
|
|
@ -92,9 +92,9 @@ def test_query_schema_execute():
|
||||||
def test_schema_get_type_map():
|
def test_schema_get_type_map():
|
||||||
assert_equal_lists(
|
assert_equal_lists(
|
||||||
schema.schema.get_type_map().keys(),
|
schema.schema.get_type_map().keys(),
|
||||||
['__Field', 'String', 'Pet', 'Character', '__InputValue', '__Directive',
|
['__Field', 'String', 'Pet', 'Character', '__InputValue',
|
||||||
'__TypeKind', '__Schema', '__Type', 'Human', '__EnumValue', 'Boolean']
|
'__Directive', '__TypeKind', '__Schema', '__Type', 'Human',
|
||||||
)
|
'__EnumValue', 'Boolean'])
|
||||||
|
|
||||||
|
|
||||||
def test_schema_no_query():
|
def test_schema_no_query():
|
||||||
|
|
|
@ -5,5 +5,26 @@ from .objecttype import ObjectTypeMeta, BaseObjectType, Interface, ObjectType, M
|
||||||
from .scalars import String, ID, Boolean, Int, Float, Scalar
|
from .scalars import String, ID, Boolean, Int, Float, Scalar
|
||||||
from .field import Field, InputField
|
from .field import Field, InputField
|
||||||
|
|
||||||
__all__ = ['BaseType', 'LazyType', 'OrderedType', 'Argument', 'ArgumentsGroup', 'to_arguments', 'List', 'NonNull', 'Field', 'InputField',
|
__all__ = [
|
||||||
'Interface', 'BaseObjectType', 'ObjectTypeMeta', 'ObjectType', 'Mutation', 'InputObjectType', 'String', 'ID', 'Boolean', 'Int', 'Float', 'Scalar']
|
'BaseType',
|
||||||
|
'LazyType',
|
||||||
|
'OrderedType',
|
||||||
|
'Argument',
|
||||||
|
'ArgumentsGroup',
|
||||||
|
'to_arguments',
|
||||||
|
'List',
|
||||||
|
'NonNull',
|
||||||
|
'Field',
|
||||||
|
'InputField',
|
||||||
|
'Interface',
|
||||||
|
'BaseObjectType',
|
||||||
|
'ObjectTypeMeta',
|
||||||
|
'ObjectType',
|
||||||
|
'Mutation',
|
||||||
|
'InputObjectType',
|
||||||
|
'String',
|
||||||
|
'ID',
|
||||||
|
'Boolean',
|
||||||
|
'Int',
|
||||||
|
'Float',
|
||||||
|
'Scalar']
|
||||||
|
|
|
@ -9,7 +9,8 @@ from .base import ArgumentType, BaseType, OrderedType
|
||||||
|
|
||||||
class Argument(OrderedType):
|
class Argument(OrderedType):
|
||||||
|
|
||||||
def __init__(self, type, description=None, default=None, name=None, _creation_counter=None):
|
def __init__(self, type, description=None, default=None,
|
||||||
|
name=None, _creation_counter=None):
|
||||||
super(Argument, self).__init__(_creation_counter=_creation_counter)
|
super(Argument, self).__init__(_creation_counter=_creation_counter)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = type
|
self.type = type
|
||||||
|
@ -17,7 +18,9 @@ class Argument(OrderedType):
|
||||||
self.default = default
|
self.default = default
|
||||||
|
|
||||||
def internal_type(self, schema):
|
def internal_type(self, schema):
|
||||||
return GraphQLArgument(schema.T(self.type), self.default, self.description)
|
return GraphQLArgument(
|
||||||
|
schema.T(self.type),
|
||||||
|
self.default, self.description)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -30,7 +33,8 @@ class ArgumentsGroup(BaseType):
|
||||||
self.arguments = OrderedDict([(arg.name, arg) for arg in arguments])
|
self.arguments = OrderedDict([(arg.name, arg) for arg in arguments])
|
||||||
|
|
||||||
def internal_type(self, schema):
|
def internal_type(self, schema):
|
||||||
return OrderedDict([(arg.name, schema.T(arg)) for arg in self.arguments.values()])
|
return OrderedDict([(arg.name, schema.T(arg))
|
||||||
|
for arg in self.arguments.values()])
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.arguments)
|
return len(self.arguments)
|
||||||
|
|
|
@ -54,7 +54,7 @@ class OrderedType(MountType):
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
# Needed for @total_ordering
|
# Needed for @total_ordering
|
||||||
if type(self) == type(other):
|
if isinstance(self, type(other)):
|
||||||
return self.creation_counter == other.creation_counter
|
return self.creation_counter == other.creation_counter
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
@ -87,7 +87,8 @@ class ArgumentType(MirroredType):
|
||||||
|
|
||||||
def as_argument(self):
|
def as_argument(self):
|
||||||
from .argument import Argument
|
from .argument import Argument
|
||||||
return Argument(self, _creation_counter=self.creation_counter, *self.args, **self.kwargs)
|
return Argument(
|
||||||
|
self, _creation_counter=self.creation_counter, *self.args, **self.kwargs)
|
||||||
|
|
||||||
|
|
||||||
class FieldType(MirroredType):
|
class FieldType(MirroredType):
|
||||||
|
@ -103,11 +104,13 @@ class FieldType(MirroredType):
|
||||||
|
|
||||||
def as_field(self):
|
def as_field(self):
|
||||||
from .field import Field
|
from .field import Field
|
||||||
return Field(self, _creation_counter=self.creation_counter, *self.args, **self.kwargs)
|
return Field(self, _creation_counter=self.creation_counter,
|
||||||
|
*self.args, **self.kwargs)
|
||||||
|
|
||||||
def as_inputfield(self):
|
def as_inputfield(self):
|
||||||
from .field import InputField
|
from .field import InputField
|
||||||
return InputField(self, _creation_counter=self.creation_counter, *self.args, **self.kwargs)
|
return InputField(
|
||||||
|
self, _creation_counter=self.creation_counter, *self.args, **self.kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MountedType(FieldType, ArgumentType):
|
class MountedType(FieldType, ArgumentType):
|
||||||
|
|
|
@ -26,7 +26,9 @@ class Empty(object):
|
||||||
|
|
||||||
class Field(OrderedType):
|
class Field(OrderedType):
|
||||||
|
|
||||||
def __init__(self, type, description=None, args=None, name=None, resolver=None, required=False, default=None, *args_list, **kwargs):
|
def __init__(
|
||||||
|
self, type, description=None, args=None, name=None, resolver=None,
|
||||||
|
required=False, default=None, *args_list, **kwargs):
|
||||||
_creation_counter = kwargs.pop('_creation_counter', None)
|
_creation_counter = kwargs.pop('_creation_counter', None)
|
||||||
super(Field, self).__init__(_creation_counter=_creation_counter)
|
super(Field, self).__init__(_creation_counter=_creation_counter)
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -43,7 +45,8 @@ class Field(OrderedType):
|
||||||
|
|
||||||
def contribute_to_class(self, cls, attname):
|
def contribute_to_class(self, cls, attname):
|
||||||
assert issubclass(
|
assert issubclass(
|
||||||
cls, BaseObjectType), 'Field {} cannot be mounted in {}'.format(self, cls)
|
cls, BaseObjectType), 'Field {} cannot be mounted in {}'.format(
|
||||||
|
self, cls)
|
||||||
if not self.name:
|
if not self.name:
|
||||||
self.name = to_camel_case(attname)
|
self.name = to_camel_case(attname)
|
||||||
self.attname = attname
|
self.attname = attname
|
||||||
|
@ -109,7 +112,7 @@ class Field(OrderedType):
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
eq = super(Field, self).__eq__(other)
|
eq = super(Field, self).__eq__(other)
|
||||||
if type(self) == type(other):
|
if isinstance(self, type(other)):
|
||||||
return eq and self.object_type == other.object_type
|
return eq and self.object_type == other.object_type
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
@ -119,7 +122,8 @@ class Field(OrderedType):
|
||||||
|
|
||||||
class InputField(OrderedType):
|
class InputField(OrderedType):
|
||||||
|
|
||||||
def __init__(self, type, description=None, default=None, name=None, _creation_counter=None, required=False):
|
def __init__(self, type, description=None, default=None,
|
||||||
|
name=None, _creation_counter=None, required=False):
|
||||||
super(InputField, self).__init__(_creation_counter=_creation_counter)
|
super(InputField, self).__init__(_creation_counter=_creation_counter)
|
||||||
self.name = name
|
self.name = name
|
||||||
if required:
|
if required:
|
||||||
|
@ -130,7 +134,8 @@ class InputField(OrderedType):
|
||||||
|
|
||||||
def contribute_to_class(self, cls, attname):
|
def contribute_to_class(self, cls, attname):
|
||||||
assert issubclass(
|
assert issubclass(
|
||||||
cls, InputObjectType), 'InputField {} cannot be mounted in {}'.format(self, cls)
|
cls, InputObjectType), 'InputField {} cannot be mounted in {}'.format(
|
||||||
|
self, cls)
|
||||||
if not self.name:
|
if not self.name:
|
||||||
self.name = to_camel_case(attname)
|
self.name = to_camel_case(attname)
|
||||||
self.attname = attname
|
self.attname = attname
|
||||||
|
@ -141,5 +146,6 @@ class InputField(OrderedType):
|
||||||
cls._meta.add_field(self)
|
cls._meta.add_field(self)
|
||||||
|
|
||||||
def internal_type(self, schema):
|
def internal_type(self, schema):
|
||||||
return GraphQLInputObjectField(schema.T(self.type), default_value=self.default,
|
return GraphQLInputObjectField(
|
||||||
description=self.description)
|
schema.T(self.type),
|
||||||
|
default_value=self.default, description=self.description)
|
||||||
|
|
|
@ -79,7 +79,8 @@ class ObjectTypeMeta(type):
|
||||||
# on the base classes (we cannot handle shadowed fields at the
|
# on the base classes (we cannot handle shadowed fields at the
|
||||||
# moment).
|
# moment).
|
||||||
for field in parent_fields:
|
for field in parent_fields:
|
||||||
if field.name in field_names and field.type.__class__ != field_names[field.name].type.__class__:
|
if field.name in field_names and field.type.__class__ != field_names[
|
||||||
|
field.name].type.__class__:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'Local field %r in class %r (%r) clashes '
|
'Local field %r in class %r (%r) clashes '
|
||||||
'with field with similar name from '
|
'with field with similar name from '
|
||||||
|
@ -111,7 +112,8 @@ class ObjectTypeMeta(type):
|
||||||
|
|
||||||
def add_to_class(cls, name, value):
|
def add_to_class(cls, name, value):
|
||||||
# We should call the contribute_to_class method only if it's bound
|
# We should call the contribute_to_class method only if it's bound
|
||||||
if not inspect.isclass(value) and hasattr(value, 'contribute_to_class'):
|
if not inspect.isclass(value) and hasattr(
|
||||||
|
value, 'contribute_to_class'):
|
||||||
value.contribute_to_class(cls, name)
|
value.contribute_to_class(cls, name)
|
||||||
else:
|
else:
|
||||||
setattr(cls, name, value)
|
setattr(cls, name, value)
|
||||||
|
@ -157,14 +159,16 @@ class BaseObjectType(BaseType):
|
||||||
pass
|
pass
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
"'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
|
"'%s' is an invalid keyword argument for this function" %
|
||||||
|
list(kwargs)[0])
|
||||||
|
|
||||||
signals.post_init.send(self.__class__, instance=self)
|
signals.post_init.send(self.__class__, instance=self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fields_as_arguments(cls, schema):
|
def fields_as_arguments(cls, schema):
|
||||||
return OrderedDict([(f.attname, GraphQLArgument(f.internal_type(schema)))
|
return OrderedDict(
|
||||||
for f in cls._meta.fields])
|
[(f.attname, GraphQLArgument(f.internal_type(schema)))
|
||||||
|
for f in cls._meta.fields])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve_objecttype(cls, schema, instance, *args):
|
def resolve_objecttype(cls, schema, instance, *args):
|
||||||
|
|
|
@ -28,7 +28,11 @@ def test_type_as_field_called(Field):
|
||||||
a = MountedType(2, description='A', resolver=resolver)
|
a = MountedType(2, description='A', resolver=resolver)
|
||||||
a.as_field()
|
a.as_field()
|
||||||
Field.assert_called_with(
|
Field.assert_called_with(
|
||||||
a, 2, _creation_counter=a.creation_counter, description='A', resolver=resolver)
|
a,
|
||||||
|
2,
|
||||||
|
_creation_counter=a.creation_counter,
|
||||||
|
description='A',
|
||||||
|
resolver=resolver)
|
||||||
|
|
||||||
|
|
||||||
@patch('graphene.core.types.argument.Argument')
|
@patch('graphene.core.types.argument.Argument')
|
||||||
|
|
|
@ -40,7 +40,8 @@ def test_custom_scalar():
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_literal(node):
|
def parse_literal(node):
|
||||||
if isinstance(node, ast.StringValue):
|
if isinstance(node, ast.StringValue):
|
||||||
return datetime.datetime.strptime(node.value, "%Y-%m-%dT%H:%M:%S.%f")
|
return datetime.datetime.strptime(
|
||||||
|
node.value, "%Y-%m-%dT%H:%M:%S.%f")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_value(value):
|
def parse_value(value):
|
||||||
|
|
|
@ -10,12 +10,17 @@ class ConnectionField(Field):
|
||||||
|
|
||||||
def __init__(self, field_type, resolver=None, description='',
|
def __init__(self, field_type, resolver=None, description='',
|
||||||
connection_type=None, edge_type=None, **kwargs):
|
connection_type=None, edge_type=None, **kwargs):
|
||||||
super(ConnectionField, self).__init__(field_type, resolver=resolver,
|
super(
|
||||||
before=String(),
|
ConnectionField,
|
||||||
after=String(),
|
self).__init__(
|
||||||
first=Int(),
|
field_type,
|
||||||
last=Int(),
|
resolver=resolver,
|
||||||
description=description, **kwargs)
|
before=String(),
|
||||||
|
after=String(),
|
||||||
|
first=Int(),
|
||||||
|
last=Int(),
|
||||||
|
description=description,
|
||||||
|
**kwargs)
|
||||||
self.connection_type = connection_type
|
self.connection_type = connection_type
|
||||||
self.edge_type = edge_type
|
self.edge_type = edge_type
|
||||||
|
|
||||||
|
@ -37,8 +42,9 @@ class ConnectionField(Field):
|
||||||
connection_type = self.get_connection_type(node)
|
connection_type = self.get_connection_type(node)
|
||||||
edge_type = self.get_edge_type(node)
|
edge_type = self.get_edge_type(node)
|
||||||
|
|
||||||
connection = connection_from_list(resolved, args, connection_type=connection_type,
|
connection = connection_from_list(
|
||||||
edge_type=edge_type, pageinfo_type=PageInfo)
|
resolved, args, connection_type=connection_type,
|
||||||
|
edge_type=edge_type, pageinfo_type=PageInfo)
|
||||||
connection.set_connection_data(resolved)
|
connection.set_connection_data(resolved)
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,11 @@ from graphql_relay.node.node import to_global_id
|
||||||
|
|
||||||
class PageInfo(ObjectType):
|
class PageInfo(ObjectType):
|
||||||
has_next_page = BooleanField(
|
has_next_page = BooleanField(
|
||||||
required=True, description='When paginating forwards, are there more items?')
|
required=True,
|
||||||
|
description='When paginating forwards, are there more items?')
|
||||||
has_previous_page = BooleanField(
|
has_previous_page = BooleanField(
|
||||||
required=True, description='When paginating backwards, are there more items?')
|
required=True,
|
||||||
|
description='When paginating backwards, are there more items?')
|
||||||
start_cursor = StringField(
|
start_cursor = StringField(
|
||||||
description='When paginating backwards, the cursor to continue.')
|
description='When paginating backwards, the cursor to continue.')
|
||||||
end_cursor = StringField(
|
end_cursor = StringField(
|
||||||
|
@ -35,7 +37,10 @@ class Edge(ObjectType):
|
||||||
def for_node(cls, node):
|
def for_node(cls, node):
|
||||||
from graphene.relay.utils import is_node
|
from graphene.relay.utils import is_node
|
||||||
assert is_node(node), 'ObjectTypes in a edge have to be Nodes'
|
assert is_node(node), 'ObjectTypes in a edge have to be Nodes'
|
||||||
return type('%s%s' % (node._meta.type_name, cls._meta.type_name), (cls, ), {'node_type': node})
|
return type(
|
||||||
|
'%s%s' % (node._meta.type_name, cls._meta.type_name),
|
||||||
|
(cls,),
|
||||||
|
{'node_type': node})
|
||||||
|
|
||||||
|
|
||||||
class Connection(ObjectType):
|
class Connection(ObjectType):
|
||||||
|
@ -56,7 +61,10 @@ class Connection(ObjectType):
|
||||||
from graphene.relay.utils import is_node
|
from graphene.relay.utils import is_node
|
||||||
edge_type = edge_type or Edge
|
edge_type = edge_type or Edge
|
||||||
assert is_node(node), 'ObjectTypes in a connection have to be Nodes'
|
assert is_node(node), 'ObjectTypes in a connection have to be Nodes'
|
||||||
return type('%s%s' % (node._meta.type_name, cls._meta.type_name), (cls, ), {'edge_type': edge_type.for_node(node)})
|
return type(
|
||||||
|
'%s%s' % (node._meta.type_name, cls._meta.type_name),
|
||||||
|
(cls,),
|
||||||
|
{'edge_type': edge_type.for_node(node)})
|
||||||
|
|
||||||
def set_connection_data(self, data):
|
def set_connection_data(self, data):
|
||||||
self._connection_data = data
|
self._connection_data = data
|
||||||
|
|
|
@ -2,7 +2,8 @@ from graphene.relay.types import BaseNode
|
||||||
|
|
||||||
|
|
||||||
def is_node(object_type):
|
def is_node(object_type):
|
||||||
return object_type and issubclass(object_type, BaseNode) and not is_node_type(object_type)
|
return object_type and issubclass(
|
||||||
|
object_type, BaseNode) and not is_node_type(object_type)
|
||||||
|
|
||||||
|
|
||||||
def is_node_type(object_type):
|
def is_node_type(object_type):
|
||||||
|
|
|
@ -19,11 +19,14 @@ def test_proxy_snake_dict():
|
||||||
assert p.get('three_or_for') == 3
|
assert p.get('three_or_for') == 3
|
||||||
assert 'inside' in p
|
assert 'inside' in p
|
||||||
assert 'other_camel_case' in p['inside']
|
assert 'other_camel_case' in p['inside']
|
||||||
assert sorted(p.items()) == sorted(list([('inside', ProxySnakeDict({'other_camel_case': 3})),
|
assert sorted(
|
||||||
('none', None),
|
p.items()) == sorted(
|
||||||
('three_or_for', 3),
|
list(
|
||||||
('two', 2),
|
[('inside', ProxySnakeDict({'other_camel_case': 3})),
|
||||||
('one', 1)]))
|
('none', None),
|
||||||
|
('three_or_for', 3),
|
||||||
|
('two', 2),
|
||||||
|
('one', 1)]))
|
||||||
|
|
||||||
|
|
||||||
def test_proxy_snake_dict_as_kwargs():
|
def test_proxy_snake_dict_as_kwargs():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user