Skip to content

Commit

Permalink
Add missing auto fields (#1212)
Browse files Browse the repository at this point in the history
* add missing auto fields

* add missing auto fields

* skip small auto field sometimes

* make small auto optional

* make small auto optional
  • Loading branch information
pizzapanther committed Jun 11, 2021
1 parent 623d0f2 commit e7f7d8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions graphene_django/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,19 @@ def convert_field_to_string(field, registry=None):
)


@convert_django_field.register(models.BigAutoField)
@convert_django_field.register(models.AutoField)
def convert_field_to_id(field, registry=None):
return ID(description=get_django_field_description(field), required=not field.null)


if hasattr(models, "SmallAutoField"):

@convert_django_field.register(models.SmallAutoField)
def convert_field_small_to_id(field, registry=None):
return convert_field_to_id(field, registry)


@convert_django_field.register(models.UUIDField)
def convert_field_to_uuid(field, registry=None):
return UUID(
Expand Down
9 changes: 9 additions & 0 deletions graphene_django/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ def test_should_auto_convert_id():
assert_conversion(models.AutoField, graphene.ID, primary_key=True)


def test_should_big_auto_convert_id():
assert_conversion(models.BigAutoField, graphene.ID, primary_key=True)


def test_should_small_auto_convert_id():
if hasattr(models, "SmallAutoField"):
assert_conversion(models.SmallAutoField, graphene.ID, primary_key=True)


def test_should_uuid_convert_id():
assert_conversion(models.UUIDField, graphene.UUID)

Expand Down

0 comments on commit e7f7d8d

Please sign in to comment.