graphql-python / graphene-gae

GraphQL Support for Google AppEngine [DEPRECATED - Looking for maintainers]
http://docs.graphene-python.org/projects/gae/en/latest/
BSD 3-Clause "New" or "Revised" License
117 stars 14 forks source link

TimeProperty #33

Closed Emsu closed 6 years ago

Emsu commented 7 years ago

NDB has support for TimeProperty but it seems to be missing.

In https://github.com/graphql-python/graphene-gae/blob/master/graphene_gae/ndb/converter.py#L129 I see:

converters = {
    ndb.StringProperty: convert_ndb_string_property,
    ndb.TextProperty: convert_ndb_string_property,
    ndb.BooleanProperty: convert_ndb_boolean_property,
    ndb.IntegerProperty: convert_ndb_int_property,
    ndb.FloatProperty: convert_ndb_float_property,
    ndb.JsonProperty: convert_ndb_json_property,
    ndb.DateProperty: convert_ndb_datetime_property,
    ndb.DateTimeProperty: convert_ndb_datetime_property,
    ndb.KeyProperty: convert_ndb_key_propety,
    ndb.StructuredProperty: convert_local_structured_property,
    ndb.LocalStructuredProperty: convert_local_structured_property,
    ndb.ComputedProperty: convert_computed_property
}

Is it as simple as just adding ndb.TimeProperty: convert_ndb_datetime_property?

Emsu commented 6 years ago

@syrusakbary so far the above is working for me. Might be nice to add it in since it's an NDB supported property. Or I could open a PR with the one line change?

Emsu commented 6 years ago

Just listing what ended up doing

diff --git a/api/lib/graphene_gae/ndb/converter.py b/api/lib/graphene_gae/ndb/converter.py
index 2450cd7..d580c06 100644
--- a/api/lib/graphene_gae/ndb/converter.py
+++ b/api/lib/graphene_gae/ndb/converter.py
@@ -6,7 +6,7 @@ from google.appengine.ext import ndb

 from graphene import String, Boolean, Int, Float, List, NonNull, Field, Dynamic
 from graphene.types.json import JSONString
-from graphene.types.datetime import DateTime
+from graphene.types.datetime import DateTime, Time

 from .fields import DynamicNdbKeyStringField, DynamicNdbKeyReferenceField

@@ -60,6 +60,10 @@ def convert_ndb_datetime_property(ndb_prop):
     return Field(DateTime, description=ndb_prop._name)

+def convert_ndb_time_property(ndb_prop):
+    return Field(Time, description=ndb_prop._name)
+
+
 def convert_ndb_key_propety(ndb_key_prop):
     """
     Two conventions for handling KeyProperties:
@@ -135,6 +139,7 @@ converters = {
     ndb.FloatProperty: convert_ndb_float_property,
     ndb.JsonProperty: convert_ndb_json_property,
     ndb.DateProperty: convert_ndb_datetime_property,
+    ndb.TimeProperty: convert_ndb_time_property,
     ndb.DateTimeProperty: convert_ndb_datetime_property,
     ndb.KeyProperty: convert_ndb_key_propety,
     ndb.StructuredProperty: convert_local_structured_property,
Emsu commented 6 years ago

@ekampf created PR #37 for this