mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-26 07:49:53 +03:00
Merge 45df639671
into bd1fbb6a33
This commit is contained in:
commit
dbc763eea1
|
@ -28,12 +28,12 @@ def convert_django_field_with_choices(field):
|
|||
meta = field.model._meta
|
||||
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
|
||||
graphql_choices = list(convert_choices(choices))
|
||||
return Enum(name.upper(), graphql_choices, description=field.help_text)
|
||||
return convert_django_field(field, Enum(name.upper(), graphql_choices, description=field.help_text))
|
||||
return convert_django_field(field)
|
||||
|
||||
|
||||
@singledispatch
|
||||
def convert_django_field(field):
|
||||
def convert_django_field(field, enum=None):
|
||||
raise Exception(
|
||||
"Don't know how to convert the Django field %s (%s)" %
|
||||
(field, field.__class__))
|
||||
|
@ -47,12 +47,16 @@ def convert_django_field(field):
|
|||
@convert_django_field.register(models.GenericIPAddressField)
|
||||
@convert_django_field.register(models.FileField)
|
||||
@convert_django_field.register(UUIDField)
|
||||
def convert_field_to_string(field):
|
||||
def convert_field_to_string(field, enum=None):
|
||||
if enum is not None:
|
||||
return String(enum)
|
||||
return String(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.AutoField)
|
||||
def convert_field_to_id(field):
|
||||
def convert_field_to_id(field, enum=None):
|
||||
if enum is not None:
|
||||
return ID(enum)
|
||||
return ID(description=field.help_text)
|
||||
|
||||
|
||||
|
@ -61,28 +65,38 @@ def convert_field_to_id(field):
|
|||
@convert_django_field.register(models.SmallIntegerField)
|
||||
@convert_django_field.register(models.BigIntegerField)
|
||||
@convert_django_field.register(models.IntegerField)
|
||||
def convert_field_to_int(field):
|
||||
def convert_field_to_int(field, enum=None):
|
||||
if enum is not None:
|
||||
return Int(enum)
|
||||
return Int(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.BooleanField)
|
||||
def convert_field_to_boolean(field):
|
||||
def convert_field_to_boolean(field, enum=None):
|
||||
if enum is not None:
|
||||
return Boolean(enum)
|
||||
return Boolean(description=field.help_text, required=True)
|
||||
|
||||
|
||||
@convert_django_field.register(models.NullBooleanField)
|
||||
def convert_field_to_nullboolean(field):
|
||||
def convert_field_to_nullboolean(field, enum=None):
|
||||
if enum is not None:
|
||||
return Boolean(enum)
|
||||
return Boolean(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.DecimalField)
|
||||
@convert_django_field.register(models.FloatField)
|
||||
def convert_field_to_float(field):
|
||||
def convert_field_to_float(field, enum=None):
|
||||
if enum is not None:
|
||||
return Float(enum)
|
||||
return Float(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.DateField)
|
||||
def convert_date_to_string(field):
|
||||
def convert_date_to_string(field, enum=None):
|
||||
if enum is not None:
|
||||
return DateTime(enum)
|
||||
return DateTime(description=field.help_text)
|
||||
|
||||
|
||||
|
|
|
@ -52,8 +52,9 @@ class InstanceObjectType(ObjectType):
|
|||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def __init__(self, _root=None):
|
||||
super(InstanceObjectType, self).__init__(_root=_root)
|
||||
def __init__(self, _root=None, **kwargs):
|
||||
kwargs['_root'] = _root
|
||||
super(InstanceObjectType, self).__init__(**kwargs)
|
||||
assert not self._root or isinstance(self._root, self._meta.model), (
|
||||
'{} received a non-compatible instance ({}) '
|
||||
'when expecting {}'.format(
|
||||
|
|
Loading…
Reference in New Issue
Block a user