Skip to content

Commit

Permalink
Merge 64cca49 into 617eaad
Browse files Browse the repository at this point in the history
  • Loading branch information
abawchen committed May 13, 2019
2 parents 617eaad + 64cca49 commit 80e6ee4
Showing 1 changed file with 31 additions and 39 deletions.
70 changes: 31 additions & 39 deletions graphene_mongo/advanced_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,67 @@
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)


def _resolve_content_type(self, info):
return _resolve_fs_field(self, 'content_type')


def _resolve_md5(self, info):
return _resolve_fs_field(self, 'md5')


def _resolve_chunk_size(self, info):
return _resolve_fs_field(self, 'chunk_size', 0)

class FileFieldType(graphene.ObjectType):

def _resolve_length(self, info):
return _resolve_fs_field(self, 'length', 0)
content_type = graphene.String()
md5 = graphene.String()
chunk_size = graphene.Int()
length = graphene.Int()
data = graphene.String()

def resolve_content_type(self, info):
return _resolve_fs_field(self, 'content_type')

def _resolve_data(self, info):
v = getattr(self.instance, self.key)
data = v.read()
if data is not None:
return base64.b64encode(data)
return None
def resolve_md5(self, info):
return _resolve_fs_field(self, 'md5')

def resolve_chunk_size(self, info):
return _resolve_fs_field(self, 'chunk_size', 0)

class FileFieldType(graphene.ObjectType):
def resolve_length(self, info):
return _resolve_fs_field(self, 'length', 0)

content_type = graphene.String(resolver=_resolve_content_type)
md5 = graphene.String(resolver=_resolve_md5)
chunk_size = graphene.Int(resolver=_resolve_chunk_size)
length = graphene.Int(resolver=_resolve_length)
data = graphene.String(resolver=_resolve_data)
def resolve_data(self, info):
v = getattr(self.instance, self.key)
data = v.read()
if data is not None:
return base64.b64encode(data)
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 80e6ee4

Please sign in to comment.