From e7f7d8da07ba1020f9916153f17e97b0ec037712 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Fri, 11 Jun 2021 15:41:02 -0500 Subject: [PATCH] Add missing auto fields (#1212) * add missing auto fields * add missing auto fields * skip small auto field sometimes * make small auto optional * make small auto optional --- graphene_django/converter.py | 8 ++++++++ graphene_django/tests/test_converter.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/graphene_django/converter.py b/graphene_django/converter.py index da96161..c243e82 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -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( diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index fe84e73..afd744f 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -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)