mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Improved field description converter from Django fields
This commit is contained in:
parent
fe510dc686
commit
0843499306
|
@ -26,12 +26,12 @@ def convert_django_field(field):
|
|||
@convert_django_field.register(models.URLField)
|
||||
@convert_django_field.register(models.UUIDField)
|
||||
def _(field):
|
||||
return StringField(description=field.description)
|
||||
return StringField(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.AutoField)
|
||||
def _(field):
|
||||
return IDField(description=field.description)
|
||||
return IDField(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.PositiveIntegerField)
|
||||
|
@ -40,22 +40,22 @@ def _(field):
|
|||
@convert_django_field.register(models.BigIntegerField)
|
||||
@convert_django_field.register(models.IntegerField)
|
||||
def _(field):
|
||||
return IntField(description=field.description)
|
||||
return IntField(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.BooleanField)
|
||||
def _(field):
|
||||
return BooleanField(description=field.description, required=True)
|
||||
return BooleanField(description=field.help_text, required=True)
|
||||
|
||||
|
||||
@convert_django_field.register(models.NullBooleanField)
|
||||
def _(field):
|
||||
return BooleanField(description=field.description)
|
||||
return BooleanField(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.FloatField)
|
||||
def _(field):
|
||||
return FloatField(description=field.description)
|
||||
return FloatField(description=field.help_text)
|
||||
|
||||
|
||||
@convert_django_field.register(models.ManyToManyField)
|
||||
|
@ -68,4 +68,4 @@ def _(field):
|
|||
@convert_django_field.register(models.OneToOneField)
|
||||
@convert_django_field.register(models.ForeignKey)
|
||||
def _(field):
|
||||
return DjangoModelField(field.related_model, description=field.description)
|
||||
return DjangoModelField(field.related_model, description=field.help_text)
|
||||
|
|
|
@ -100,6 +100,7 @@ class Field(object):
|
|||
internal_type = self.internal_type(schema)
|
||||
if not internal_type:
|
||||
raise Exception("Internal type for field %s is None" % self)
|
||||
|
||||
return GraphQLField(
|
||||
internal_type,
|
||||
description=self.description,
|
||||
|
|
|
@ -15,9 +15,10 @@ from .models import Article, Reporter
|
|||
|
||||
|
||||
def assert_conversion(django_field, graphene_field, *args):
|
||||
field = django_field(*args)
|
||||
field = django_field(*args, help_text='Custom Help Text')
|
||||
graphene_type = convert_django_field(field)
|
||||
assert isinstance(graphene_type, graphene_field)
|
||||
assert graphene_type.description == 'Custom Help Text'
|
||||
return graphene_type
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user