From 6ba2db3c61de69ff6c65d36660797bf7b668ab06 Mon Sep 17 00:00:00 2001 From: AbawChen Date: Mon, 13 May 2019 10:59:15 +0800 Subject: [PATCH] refactor: Move _resolve_fs_field into FileFieldType as a classmethod --- graphene_mongo/advanced_types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/graphene_mongo/advanced_types.py b/graphene_mongo/advanced_types.py index 216d33f5..e7769507 100644 --- a/graphene_mongo/advanced_types.py +++ b/graphene_mongo/advanced_types.py @@ -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() @@ -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)