Skip to content

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

Add validate for query param should be a valid string

nixeb32ed2b47f6
diff --git a/saleor/graphql/views.py b/saleor/graphql/views.py
index 7f8c14dcbb..f462e56531 100644
--- a/saleor/graphql/views.py
+++ b/saleor/graphql/views.py
@@ -113,11 +113,11 @@ class GraphQLView(View):
def parse_query(self, query: str) -> (GraphQLDocument, ExecutionResult):
"""Attempt to parse a query (mandatory) to a gql document object.
- If no query was given, it returns an error.
+ If no query was given or query is not a string, it returns an error.
If the query is invalid, it returns an error as well.
Otherwise, it returns the parsed gql document.
"""
- if not query:
+ if not query or not isinstance(query, str):
return (
None,
ExecutionResult(
diff --git a/tests/api/test_view.py b/tests/api/test_view.py
index d77d08f6f7..4ee81f7968 100644
--- a/tests/api/test_view.py
+++ b/tests/api/test_view.py
@@ -108,6 +108,14 @@ def test_no_query(client):
assert content["errors"][0]["message"] == "Must provide a query string."
+def test_query_is_dict(client):
+ data = {"query": {"type": "dict"}}
+ response = client.post(API_PATH, data, content_type="application/json")
+ assert response.status_code == 400
+ content = _get_graphql_content_from_response(response)
+ assert content["errors"][0]["message"] == "Must provide a query string."
+
+
def test_graphql_execution_exception(monkeypatch, api_client):
def mocked_execute(*args, **kwargs):
raise IOError("Spanish inquisition")