Skip to content

Commit b4d8672

Browse files
committed
baseapp-core: wip
1 parent 46926c6 commit b4d8672

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

baseapp-core/baseapp_core/graphql/fields.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import graphene
2+
from django.apps import apps
23
from django.conf import settings
34
from django.core.cache import InvalidCacheBackendError, caches
45
from easy_thumbnails.files import get_thumbnailer
@@ -8,15 +9,24 @@
89
except 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()
20+
21+
class Meta:
22+
name = "File"
23+
24+
return FileObjectType
1125

12-
class File(graphene.ObjectType):
13-
url = graphene.String(required=True)
14-
# contentType = graphene.String()
15-
# bytes = graphene.Int()
1626

1727

1828
class ThumbnailField(graphene.Field):
19-
def __init__(self, type=File, **kwargs):
29+
def __init__(self, type=get_file_object_type, **kwargs):
2030
kwargs.update(
2131
{
2232
"args": {
@@ -29,6 +39,7 @@ def __init__(self, type=File, **kwargs):
2939

3040
def get_resolver(self, parent_resolver):
3141
resolver = self.resolver or parent_resolver
42+
FileObjectType = get_file_object_type()
3243

3344
def built_thumbnail(instance, info, width, height, **kwargs):
3445
instance = resolver(instance, info, **kwargs)
@@ -40,7 +51,7 @@ def built_thumbnail(instance, info, width, height, **kwargs):
4051
cache_key = self._get_cache_key(instance, width, height)
4152
value_from_cache = cache.get(cache_key)
4253
if value_from_cache:
43-
return File(url=value_from_cache)
54+
return FileObjectType(url=value_from_cache)
4455

4556
thumbnailer = get_thumbnailer(instance)
4657
url = thumbnailer.get_thumbnail({"size": (width, height)}).url
@@ -49,7 +60,7 @@ def built_thumbnail(instance, info, width, height, **kwargs):
4960
if cache:
5061
cache.set(cache_key, absolute_url, timeout=None)
5162

52-
return File(url=absolute_url)
63+
return FileObjectType(url=absolute_url)
5364

5465
return built_thumbnail
5566

baseapp-core/baseapp_core/graphql/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from graphene_django.views import HttpError
66
from graphql import get_operation_ast, parse
77
from graphql.execution import ExecutionResult
8-
from graphene_file_upload.utils import place_files_in_operations
8+
# from graphene_file_upload.utils import place_files_in_operations
99

1010
try:
1111
import sentry_sdk

baseapp-core/setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = baseapp-core
3-
version = 0.2.11
3+
version = 0.2.12
44
description = BaseApp Core
55
long_description = file: README.md
66
url = https://github.com/silverlogic/baseapp-backend
@@ -24,6 +24,7 @@ install_requires =
2424
djangorestframework >= 3.14
2525
drf-nested-routers >= 0.93.5
2626
djangorestframework-expander >= 0.2
27+
djangorestframework-simplejwt >= 5.3
2728
drf-extra-fields >= 3.5
2829
psycopg2-binary >= 2.9
2930
django-phonenumber-field >= 7.0

0 commit comments

Comments
 (0)