Skip to content

Commit 58f009b

Browse files
committed
Merge pull request #1 from amitsaha/multipart
Add support for multipart/form-data
2 parents 87723fd + 1990015 commit 58f009b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: graphql_flask/graphqlview.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def json_encode(self, request, d):
9595
# noinspection PyBroadException
9696
def parse_body(self, request):
9797
content_type = self.get_content_type(request)
98-
9998
if content_type == 'application/graphql':
10099
return {'query': request.data.decode()}
101100

@@ -110,6 +109,9 @@ def parse_body(self, request):
110109
elif content_type == 'application/x-www-form-urlencoded':
111110
return request.form
112111

112+
elif content_type == 'multipart/form-data':
113+
return request.form
114+
113115
return {}
114116

115117
def _execute(self, *args, **kwargs):

Diff for: tests/test_graphqlview.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import pytest
22
import json
33

4+
try:
5+
from StringIO import StringIO
6+
except ImportError:
7+
from io import StringIO
8+
49
try:
510
from urllib import urlencode
611
except ImportError:
@@ -420,3 +425,17 @@ def test_passes_request_into_request_context(client):
420425
'request': 'testing'
421426
}
422427
}
428+
429+
def test_post_multipart_data(client):
430+
query = 'mutation TestMutation { writeTest { test } }'
431+
response = client.post(
432+
url_string(),
433+
data= {
434+
'query': query,
435+
'file': (StringIO(), 'text1.txt'),
436+
},
437+
content_type='multipart/form-data'
438+
)
439+
440+
assert response.status_code == 200
441+
assert response_json(response) == {'data': {u'writeTest': {u'test': u'Hello World'}}}

0 commit comments

Comments
 (0)