Skip to content

Commit c6d5196

Browse files
authored
Merge pull request #58 from graphql-python/feat-point-field
feat: Support PointField
2 parents 25acbd9 + 907797c commit c6d5196

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

graphene_mongo/converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def convert_field_to_float(field, registry=None):
6060

6161
@convert_mongoengine_field.register(mongoengine.DictField)
6262
@convert_mongoengine_field.register(mongoengine.MapField)
63+
@convert_mongoengine_field.register(mongoengine.PointField)
6364
def convert_dict_to_jsonstring(field, registry=None):
6465
return JSONString(description=field.db_field, required=field.required)
6566

graphene_mongo/tests/models.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mongoengine.fields import (
66
DateTimeField, EmailField, EmbeddedDocumentField,
77
FloatField, EmbeddedDocumentListField, ListField,
8-
MapField, ReferenceField, StringField
8+
MapField, PointField, ReferenceField, StringField
99
)
1010

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

2222

23-
class Pet(Document):
24-
25-
meta = {'collection': 'test_pet'}
26-
name = StringField(max_length=16, required=True)
27-
reporter_id = StringField()
28-
29-
3023
class Article(Document):
3124

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

8376
meta = {'collection': 'test_child'}
8477
baz = StringField()
78+
loc = PointField()
8579

8680

8781
class ProfessorMetadata(EmbeddedDocument):

graphene_mongo/tests/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Article, Editor, EmbeddedArticle, Player,
66
Reporter, Child, ProfessorMetadata, ProfessorVector,
77
ChildRegisteredBefore, ChildRegisteredAfter,
8-
ParentWithRelationship
8+
ParentWithRelationship,
99
)
1010

1111

@@ -95,7 +95,7 @@ def fixtures():
9595
child1 = Child(bar='BAR', baz='BAZ')
9696
child1.save()
9797

98-
child2 = Child(bar='bar', baz='baz')
98+
child2 = Child(bar='bar', baz='baz', loc=[10, 20])
9999
child2.save()
100100

101101
ProfessorVector.drop_collection()

graphene_mongo/tests/test_converter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ def test_should_dict_convert_json():
7878
assert_conversion(mongoengine.DictField, graphene.JSONString)
7979

8080

81-
def test_should_convert_map_to_json():
81+
def test_should_map_convertjson():
8282
assert_conversion(mongoengine.MapField, graphene.JSONString, field=mongoengine.StringField())
8383

8484

85+
def test_should_point_convert_json():
86+
assert_conversion(mongoengine.PointField, graphene.JSONString)
87+
88+
8589
def test_should_field_convert_list():
8690
assert_conversion(mongoengine.ListField, graphene.List, field=mongoengine.StringField())
8791

graphene_mongo/tests/test_relay_query.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ class Query(graphene.ObjectType):
300300
edges {
301301
node {
302302
bar,
303-
baz
303+
baz,
304+
loc
304305
}
305306
}
306307
}
@@ -318,11 +319,19 @@ class Query(graphene.ObjectType):
318319
]
319320
}
320321
}
322+
loc = {
323+
'type': 'Point',
324+
'coordinates': [10, 20]
325+
}
326+
loc_json_string = json.dumps(loc, sort_keys=True)
321327
schema = graphene.Schema(query=Query)
328+
322329
result = schema.execute(query)
330+
result_loc = json.loads(result.data['children']['edges'][0]['node'].pop('loc'))
323331
assert not result.errors
324332
assert json.dumps(result.data, sort_keys=True) == json.dumps(
325333
expected, sort_keys=True)
334+
assert json.dumps(result_loc, sort_keys=True) == loc_json_string
326335

327336

328337
def test_should_get_node_by_id(fixtures):

0 commit comments

Comments
 (0)