Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Rename FileUploadGraphQLView to GraphQLView

Marcin Gębalae44add72ba31
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
index 11694b9352..7d378ba2c4 100644
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -11,9 +11,8 @@ from graphql_jwt.exceptions import JSONWebTokenError, PermissionDenied
from ...account import models
from ..account.types import User
-from ..file_upload.types import Upload
from ..utils import get_nodes
-from .types.common import Error
+from .types import Error, Upload
from .utils import snake_to_camel_case
registry = get_global_registry()
diff --git a/saleor/graphql/core/types/__init__.py b/saleor/graphql/core/types/__init__.py
index 45145df98c..a2da5750a9 100644
--- a/saleor/graphql/core/types/__init__.py
+++ b/saleor/graphql/core/types/__init__.py
@@ -5,3 +5,4 @@ from .common import (
from .money import (
Money, MoneyRange, ReducedRate, TaxedMoney, TaxedMoneyRange, TaxRateType,
VAT)
+from .upload import Upload
diff --git a/saleor/graphql/file_upload/types.py b/saleor/graphql/core/types/upload.py
similarity index 100%
rename from saleor/graphql/file_upload/types.py
rename to saleor/graphql/core/types/upload.py
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 7c8f891b3d..7a52cbb345 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -12,10 +12,8 @@ from ....product.thumbnails import (
create_collection_background_image_thumbnails, create_product_thumbnails)
from ....product.utils.attributes import get_name_from_attributes
from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
-from ...core.types.common import Decimal, SeoInput
-from ...core.types.money import TaxRateType
+from ...core.types import Decimal, SeoInput, TaxRateType, Upload
from ...core.utils import clean_seo_fields
-from ...file_upload.types import Upload
from ...shipping.types import WeightScalar
from ..types import Category, Collection, Product, ProductImage, ProductVariant
from ..utils import attributes_to_hstore
diff --git a/saleor/graphql/file_upload/views.py b/saleor/graphql/views.py
similarity index 93%
rename from saleor/graphql/file_upload/views.py
rename to saleor/graphql/views.py
index 323e248225..e2a061ec5b 100644
--- a/saleor/graphql/file_upload/views.py
+++ b/saleor/graphql/views.py
@@ -11,9 +11,13 @@ from graphql.error import GraphQLError, format_error as format_graphql_error
from graphql.execution import ExecutionResult
-class FileUploadGraphQLView(View):
- # This class was inspired by the `FileUploadGraphQLView` class from
- # https://github.com/lmcgartland/graphene-file-upload
+class GraphQLView(View):
+ # This class is our implementation of `graphene_django.views.GraphQLView`,
+ # which was extended to support the following features:
+ # - Playground as default API explorer (https://github.com/prisma/graphql-playground)
+ # - file upload (see `FileUploadGraphQLView`) from https://github.com/lmcgartland/graphene-file-upload
+ # - query batching
+
schema = None
executor = None
backend = None
@@ -21,11 +25,7 @@ class FileUploadGraphQLView(View):
root_value = None
def __init__(
- self,
- schema=None,
- executor=None,
- middleware=None,
- root_value=None,
+ self, schema=None, executor=None, middleware=None, root_value=None,
backend=None):
if schema is None:
schema = graphene_settings.SCHEMA
@@ -74,9 +74,7 @@ class FileUploadGraphQLView(View):
default=200)
else:
result, status_code = self.get_response(request, data)
- return JsonResponse(
- data=result,
- status=status_code)
+ return JsonResponse(data=result, status=status_code, safe=False)
def get_response(self, request: HttpRequest, data: dict):
query, variables, operation_name = self.get_graphql_params(
diff --git a/saleor/urls.py b/saleor/urls.py
index 78f2b4244f..d8b604c11d 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -15,7 +15,7 @@ from .core.urls import urlpatterns as core_urls
from .dashboard.urls import urlpatterns as dashboard_urls
from .data_feeds.urls import urlpatterns as feed_urls
from .graphql.api import schema
-from .graphql.file_upload.views import FileUploadGraphQLView
+from .graphql.views import GraphQLView
from .order.urls import urlpatterns as order_urls
from .page.urls import urlpatterns as page_urls
from .product.urls import urlpatterns as product_urls
@@ -26,7 +26,7 @@ handler404 = 'saleor.core.views.handle_404'
non_translatable_urlpatterns = [
url(r'^dashboard/',
include((dashboard_urls, 'dashboard'), namespace='dashboard')),
- url(r'^graphql/', csrf_exempt(FileUploadGraphQLView.as_view(
+ url(r'^graphql/', csrf_exempt(GraphQLView.as_view(
schema=schema)), name='api'),
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),