Skip to content

Commit

Permalink
refactor: Move resolve_coordinates into _CoordinatesTypeField
Browse files Browse the repository at this point in the history
  • Loading branch information
abawchen committed May 13, 2019
1 parent 4203aa4 commit 64cca49
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions graphene_mongo/advanced_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import graphene


def _resolve_type_coordinates(self, info):
return self['coordinates']


def _resolve_fs_field(field, name, default_value=None):
v = getattr(field.instance, field.key)
return getattr(v, name, default_value)
Expand Down Expand Up @@ -39,33 +35,34 @@ def resolve_data(self, info):
return None


class _TypeField(graphene.ObjectType):
class _CoordinatesTypeField(graphene.ObjectType):

type = graphene.String()

def resolve_type(self, info):
return self['type']

def resolve_coordinates(self, info):
return self['coordinates']

class PointFieldType(_TypeField):

coordinates = graphene.List(
graphene.Float, resolver=_resolve_type_coordinates)
class PointFieldType(_CoordinatesTypeField):

coordinates = graphene.List(graphene.Float)

class PolygonFieldType(_TypeField):

class PolygonFieldType(_CoordinatesTypeField):

coordinates = graphene.List(
graphene.List(
graphene.List(graphene.Float)),
resolver=_resolve_type_coordinates
graphene.List(graphene.Float))
)


class MultiPolygonFieldType(_TypeField):
class MultiPolygonFieldType(_CoordinatesTypeField):

coordinates = graphene.List(
graphene.List(
graphene.List(
graphene.List(graphene.Float))),
resolver=_resolve_type_coordinates)
graphene.List(graphene.Float)))
)

0 comments on commit 64cca49

Please sign in to comment.