Skip to content

Commit 9ef98e3

Browse files
committed
wip: Add FsFileType.data and its resolver
1 parent f49f54e commit 9ef98e3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

graphene_mongo/advanced_types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import mongoengine
23
import graphene
34

@@ -8,6 +9,12 @@ def _resolve_type_coordinates(self, info):
89
return self['coordinates']
910

1011

12+
def _resolve_data(self, info):
13+
v = getattr(self.instance, self.key)
14+
data = v.read()
15+
return base64.b64encode(data)
16+
17+
1118
class FsFile(mongoengine.Document):
1219

1320
meta = {'collection': 'fs.files'}
@@ -22,6 +29,8 @@ class FsFileType(MongoengineObjectType):
2229
class Meta:
2330
model = FsFile
2431

32+
data = graphene.String(resolver=_resolve_data)
33+
2534

2635
class _TypeField(graphene.ObjectType):
2736

graphene_mongo/tests/setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ def fixtures():
3131
editor1.avatar.put(f, content_type='image/jpeg')
3232
editor1.save()
3333

34-
"""
3534
e = Editor.objects(first_name='Penny').first()
3635
avatar = e.avatar.read()
3736
print(e.avatar.content_type)
38-
"""
37+
print(e.avatar.chunk_size)
38+
print(e.avatar.md5)
39+
print(type(avatar))
3940

4041
editor2 = Editor(
4142
id='2',

graphene_mongo/tests/test_query.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def resolve_editors(self, *args, **kwargs):
3636
contentType,
3737
chunkSize,
3838
length,
39-
md5
39+
md5,
40+
chunk
4041
}
4142
}
4243
editors {
@@ -53,7 +54,8 @@ def resolve_editors(self, *args, **kwargs):
5354
'contentType': 'image/jpeg',
5455
'chunkSize': 261120,
5556
'length': 46928,
56-
'md5': 'f3c657fd472fdc4bc2ca9056a1ae6106'
57+
'md5': 'f3c657fd472fdc4bc2ca9056a1ae6106',
58+
'chunk': 'abc'
5759
}
5860
},
5961
'editors': [{

0 commit comments

Comments
 (0)