Skip to content

Commit

Permalink
refactor: Move _resolve_fs_field into FileFieldType as a classmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
abawchen committed May 13, 2019
1 parent 64cca49 commit 6ba2db3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions graphene_mongo/advanced_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
import graphene


def _resolve_fs_field(field, name, default_value=None):
v = getattr(field.instance, field.key)
return getattr(v, name, default_value)


class FileFieldType(graphene.ObjectType):

content_type = graphene.String()
Expand All @@ -15,17 +10,22 @@ class FileFieldType(graphene.ObjectType):
length = graphene.Int()
data = graphene.String()

@classmethod
def _resolve_fs_field(cls, 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')
return FileFieldType._resolve_fs_field(self, 'content_type')

def resolve_md5(self, info):
return _resolve_fs_field(self, 'md5')
return FileFieldType._resolve_fs_field(self, 'md5')

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

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

def resolve_data(self, info):
v = getattr(self.instance, self.key)
Expand Down

0 comments on commit 6ba2db3

Please sign in to comment.