diff --git a/graphene_django/converter.py b/graphene_django/converter.py index 70b364c..706d968 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -4,7 +4,7 @@ from django.utils.encoding import force_text from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List, NonNull, String) from graphene.relay import is_node -from graphene.types.datetime import DateTime +from graphene.types.datetime import DateTime, Time from graphene.types.json import JSONString from graphene.utils.str_converters import to_camel_case, to_const from graphql import assert_valid_name @@ -112,6 +112,11 @@ def convert_date_to_string(field, registry=None): return DateTime(description=field.help_text, required=not field.null) +@convert_django_field.register(models.TimeField) +def convert_time_to_string(field, registry=None): + return Time(description=field.help_text, required=not field.null) + + @convert_django_field.register(models.OneToOneRel) def convert_onetoone_field_to_djangomodel(field, registry=None): model = get_related_model(field) diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index 3467ed7..69be406 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -5,7 +5,7 @@ from py.test import raises import graphene from graphene.relay import ConnectionField, Node -from graphene.types.datetime import DateTime +from graphene.types.datetime import DateTime, Time from graphene.types.json import JSONString from ..compat import (ArrayField, HStoreField, JSONField, MissingType, @@ -16,7 +16,7 @@ from ..types import DjangoObjectType from .models import Article, Film, FilmDetails, Reporter -# from graphene.core.types.custom_scalars import DateTime, JSONString +# from graphene.core.types.custom_scalars import DateTime, Time, JSONString def assert_conversion(django_field, graphene_field, *args, **kwargs): @@ -44,6 +44,10 @@ def test_should_date_convert_string(): assert_conversion(models.DateField, DateTime) +def test_should_time_convert_string(): + assert_conversion(models.TimeField, Time) + + def test_should_char_convert_string(): assert_conversion(models.CharField, graphene.String) diff --git a/setup.py b/setup.py index e75a4a9..8b03620 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( install_requires=[ 'six>=1.10.0', - 'graphene>=1.0', + 'graphene>=1.1.2', 'Django>=1.6.0', 'iso8601', 'singledispatch>=3.4.0.3',