11import graphene
2+ from django .apps import apps
23from django .conf import settings
34from django .core .cache import InvalidCacheBackendError , caches
45from easy_thumbnails .files import get_thumbnailer
89except InvalidCacheBackendError :
910 cache = None
1011
12+ def get_file_object_type ():
13+ if apps .is_installed ("baseapp_files" ):
14+ from baseapp_files .graphql .object_types import FileObjectType
15+ else :
16+ class FileObjectType (graphene .ObjectType ):
17+ url = graphene .String (required = True )
18+ # contentType = graphene.String()
19+ # bytes = graphene.Int()
1120
12- class File ( graphene . ObjectType ) :
13- url = graphene . String ( required = True )
14- # contentType = graphene.String()
15- # bytes = graphene.Int()
21+ class Meta :
22+ name = "File"
23+
24+ return FileObjectType
1625
1726
1827class ThumbnailField (graphene .Field ):
19- def __init__ (self , type = File , ** kwargs ):
28+ def __init__ (self , type = get_file_object_type , ** kwargs ):
2029 kwargs .update (
2130 {
2231 "args" : {
@@ -29,6 +38,7 @@ def __init__(self, type=File, **kwargs):
2938
3039 def get_resolver (self , parent_resolver ):
3140 resolver = self .resolver or parent_resolver
41+ FileObjectType = get_file_object_type ()
3242
3343 def built_thumbnail (instance , info , width , height , ** kwargs ):
3444 instance = resolver (instance , info , ** kwargs )
@@ -40,7 +50,7 @@ def built_thumbnail(instance, info, width, height, **kwargs):
4050 cache_key = self ._get_cache_key (instance , width , height )
4151 value_from_cache = cache .get (cache_key )
4252 if value_from_cache :
43- return File (url = value_from_cache )
53+ return FileObjectType (url = value_from_cache )
4454
4555 thumbnailer = get_thumbnailer (instance )
4656 url = thumbnailer .get_thumbnail ({"size" : (width , height )}).url
@@ -49,7 +59,7 @@ def built_thumbnail(instance, info, width, height, **kwargs):
4959 if cache :
5060 cache .set (cache_key , absolute_url , timeout = None )
5161
52- return File (url = absolute_url )
62+ return FileObjectType (url = absolute_url )
5363
5464 return built_thumbnail
5565
0 commit comments