mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-27 00:09:45 +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
|
meta = field.model._meta
|
||||||
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
|
name = '{}_{}_{}'.format(meta.app_label, meta.object_name, field.name)
|
||||||
graphql_choices = list(convert_choices(choices))
|
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)
|
return convert_django_field(field)
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def convert_django_field(field):
|
def convert_django_field(field, enum=None):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Don't know how to convert the Django field %s (%s)" %
|
"Don't know how to convert the Django field %s (%s)" %
|
||||||
(field, field.__class__))
|
(field, field.__class__))
|
||||||
|
@ -47,12 +47,16 @@ def convert_django_field(field):
|
||||||
@convert_django_field.register(models.GenericIPAddressField)
|
@convert_django_field.register(models.GenericIPAddressField)
|
||||||
@convert_django_field.register(models.FileField)
|
@convert_django_field.register(models.FileField)
|
||||||
@convert_django_field.register(UUIDField)
|
@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)
|
return String(description=field.help_text)
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(models.AutoField)
|
@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)
|
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.SmallIntegerField)
|
||||||
@convert_django_field.register(models.BigIntegerField)
|
@convert_django_field.register(models.BigIntegerField)
|
||||||
@convert_django_field.register(models.IntegerField)
|
@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)
|
return Int(description=field.help_text)
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(models.BooleanField)
|
@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)
|
return Boolean(description=field.help_text, required=True)
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(models.NullBooleanField)
|
@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)
|
return Boolean(description=field.help_text)
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(models.DecimalField)
|
@convert_django_field.register(models.DecimalField)
|
||||||
@convert_django_field.register(models.FloatField)
|
@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)
|
return Float(description=field.help_text)
|
||||||
|
|
||||||
|
|
||||||
@convert_django_field.register(models.DateField)
|
@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)
|
return DateTime(description=field.help_text)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,9 @@ class InstanceObjectType(ObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def __init__(self, _root=None):
|
def __init__(self, _root=None, **kwargs):
|
||||||
super(InstanceObjectType, self).__init__(_root=_root)
|
kwargs['_root'] = _root
|
||||||
|
super(InstanceObjectType, self).__init__(**kwargs)
|
||||||
assert not self._root or isinstance(self._root, self._meta.model), (
|
assert not self._root or isinstance(self._root, self._meta.model), (
|
||||||
'{} received a non-compatible instance ({}) '
|
'{} received a non-compatible instance ({}) '
|
||||||
'when expecting {}'.format(
|
'when expecting {}'.format(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user