Skip to content

Commit

Permalink
Merge pull request #58 from graphql-python/feat-point-field
Browse files Browse the repository at this point in the history
feat: Support PointField
  • Loading branch information
abawchen committed Nov 16, 2018
2 parents 25acbd9 + 907797c commit c6d5196
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions graphene_mongo/converter.py
Expand Up @@ -60,6 +60,7 @@ def convert_field_to_float(field, registry=None):

@convert_mongoengine_field.register(mongoengine.DictField)
@convert_mongoengine_field.register(mongoengine.MapField)
@convert_mongoengine_field.register(mongoengine.PointField)
def convert_dict_to_jsonstring(field, registry=None):
return JSONString(description=field.db_field, required=field.required)

Expand Down
10 changes: 2 additions & 8 deletions graphene_mongo/tests/models.py
Expand Up @@ -5,7 +5,7 @@
from mongoengine.fields import (
DateTimeField, EmailField, EmbeddedDocumentField,
FloatField, EmbeddedDocumentListField, ListField,
MapField, ReferenceField, StringField
MapField, PointField, ReferenceField, StringField
)

connect('graphene-mongo-test', host='mongomock://localhost', alias='default')
Expand All @@ -20,13 +20,6 @@ class Editor(Document):
metadata = MapField(field=StringField())


class Pet(Document):

meta = {'collection': 'test_pet'}
name = StringField(max_length=16, required=True)
reporter_id = StringField()


class Article(Document):

meta = {'collection': 'test_article'}
Expand Down Expand Up @@ -82,6 +75,7 @@ class Child(Parent):

meta = {'collection': 'test_child'}
baz = StringField()
loc = PointField()


class ProfessorMetadata(EmbeddedDocument):
Expand Down
4 changes: 2 additions & 2 deletions graphene_mongo/tests/setup.py
Expand Up @@ -5,7 +5,7 @@
Article, Editor, EmbeddedArticle, Player,
Reporter, Child, ProfessorMetadata, ProfessorVector,
ChildRegisteredBefore, ChildRegisteredAfter,
ParentWithRelationship
ParentWithRelationship,
)


Expand Down Expand Up @@ -95,7 +95,7 @@ def fixtures():
child1 = Child(bar='BAR', baz='BAZ')
child1.save()

child2 = Child(bar='bar', baz='baz')
child2 = Child(bar='bar', baz='baz', loc=[10, 20])
child2.save()

ProfessorVector.drop_collection()
Expand Down
6 changes: 5 additions & 1 deletion graphene_mongo/tests/test_converter.py
Expand Up @@ -78,10 +78,14 @@ def test_should_dict_convert_json():
assert_conversion(mongoengine.DictField, graphene.JSONString)


def test_should_convert_map_to_json():
def test_should_map_convertjson():
assert_conversion(mongoengine.MapField, graphene.JSONString, field=mongoengine.StringField())


def test_should_point_convert_json():
assert_conversion(mongoengine.PointField, graphene.JSONString)


def test_should_field_convert_list():
assert_conversion(mongoengine.ListField, graphene.List, field=mongoengine.StringField())

Expand Down
11 changes: 10 additions & 1 deletion graphene_mongo/tests/test_relay_query.py
Expand Up @@ -300,7 +300,8 @@ class Query(graphene.ObjectType):
edges {
node {
bar,
baz
baz,
loc
}
}
}
Expand All @@ -318,11 +319,19 @@ class Query(graphene.ObjectType):
]
}
}
loc = {
'type': 'Point',
'coordinates': [10, 20]
}
loc_json_string = json.dumps(loc, sort_keys=True)
schema = graphene.Schema(query=Query)

result = schema.execute(query)
result_loc = json.loads(result.data['children']['edges'][0]['node'].pop('loc'))
assert not result.errors
assert json.dumps(result.data, sort_keys=True) == json.dumps(
expected, sort_keys=True)
assert json.dumps(result_loc, sort_keys=True) == loc_json_string


def test_should_get_node_by_id(fixtures):
Expand Down

0 comments on commit c6d5196

Please sign in to comment.