Skip to content

Commit 8576c43

Browse files
Removed unwanted conditions
1 parent fbc89fc commit 8576c43

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

graphene_mongo/advanced_types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
class FileFieldType(graphene.ObjectType):
6-
76
content_type = graphene.String()
87
md5 = graphene.String()
98
chunk_size = graphene.Int()
@@ -36,7 +35,6 @@ def resolve_data(self, info):
3635

3736

3837
class _CoordinatesTypeField(graphene.ObjectType):
39-
4038
type = graphene.String()
4139

4240
def resolve_type(self, info):
@@ -47,17 +45,19 @@ def resolve_coordinates(self, info):
4745

4846

4947
class PointFieldType(_CoordinatesTypeField):
50-
5148
coordinates = graphene.List(graphene.Float)
5249

5350

54-
class PolygonFieldType(_CoordinatesTypeField):
51+
class PointFieldInputType(graphene.InputObjectType):
52+
type = graphene.String(default_value="Point")
53+
coordinates = graphene.List(graphene.Float, required=True)
5554

55+
56+
class PolygonFieldType(_CoordinatesTypeField):
5657
coordinates = graphene.List(graphene.List(graphene.List(graphene.Float)))
5758

5859

5960
class MultiPolygonFieldType(_CoordinatesTypeField):
60-
6161
coordinates = graphene.List(
6262
graphene.List(graphene.List(graphene.List(graphene.Float)))
6363
)

graphene_mongo/fields.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
FileFieldType,
2525
PointFieldType,
2626
MultiPolygonFieldType,
27-
PolygonFieldType,
27+
PolygonFieldType, PointFieldInputType,
2828
)
2929
from .converter import convert_mongoengine_field, MongoEngineConversionError
3030
from .registry import get_global_registry
@@ -113,6 +113,7 @@ def is_filterable(k):
113113
converted.type(),
114114
(
115115
FileFieldType,
116+
PointFieldType,
116117
MultiPolygonFieldType,
117118
graphene.Union,
118119
PolygonFieldType,
@@ -172,12 +173,18 @@ def reference_args(self):
172173
def get_reference_field(r, kv):
173174
field = kv[1]
174175
mongo_field = getattr(self.model, kv[0], None)
176+
if isinstance(mongo_field, mongoengine.PointField):
177+
r.update({kv[0]: graphene.Argument(PointFieldInputType)})
178+
return r
175179
if isinstance(
176180
mongo_field,
177181
(mongoengine.LazyReferenceField, mongoengine.ReferenceField, mongoengine.GenericReferenceField),
178182
):
179183
r.update({kv[0]: graphene.ID()})
180184
return r
185+
if isinstance(mongo_field, mongoengine.GenericReferenceField):
186+
r.update({kv[0]: graphene.ID()})
187+
return r
181188
if callable(getattr(field, "get_type", None)):
182189
_type = field.get_type()
183190
if _type:
@@ -217,6 +224,8 @@ def get_queryset(self, model, info, required_fields=list(), skip=None, limit=Non
217224
mongoengine.fields.PointField):
218225
location = args.pop(arg_name, None)
219226
hydrated_references[arg_name] = location["coordinates"]
227+
if (arg_name.split('__')[0] + "__max_distance") not in args:
228+
hydrated_references[arg_name.split('__')[0] + "__max_distance"] = 10000
220229
elif arg_name == "id":
221230
hydrated_references["id"] = from_global_id(args.pop("id", None))[1]
222231
args.update(hydrated_references)
@@ -229,6 +238,7 @@ def get_queryset(self, model, info, required_fields=list(), skip=None, limit=Non
229238
args.update(queryset_or_filters)
230239
if limit is not None:
231240
if reversed:
241+
order_by = ""
232242
if self.order_by:
233243
order_by = self.order_by + ",-pk"
234244
else:

0 commit comments

Comments
 (0)