File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
app/code/Magento/GraphQl/Controller
dev/tests/integration/testsuite/Magento/GraphQl/Controller Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 19
19
use Magento \Framework \App \ResponseInterface ;
20
20
use Magento \Framework \Controller \Result \JsonFactory ;
21
21
use Magento \Framework \GraphQl \Exception \ExceptionFormatter ;
22
+ use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
22
23
use Magento \Framework \GraphQl \Query \Fields as QueryFields ;
23
24
use Magento \Framework \GraphQl \Query \QueryParser ;
24
25
use Magento \Framework \GraphQl \Query \QueryProcessor ;
@@ -208,7 +209,7 @@ public function dispatch(RequestInterface $request): ResponseInterface
208
209
);
209
210
$ statusCode = 200 ;
210
211
}
211
- } catch (SyntaxError $ error ) {
212
+ } catch (SyntaxError | GraphQlInputException $ error ) {
212
213
$ result = [
213
214
'errors ' => [FormattedError::createFromException ($ error )],
214
215
];
@@ -245,7 +246,7 @@ private function getDataFromRequest(RequestInterface $request): array
245
246
{
246
247
/** @var Http $request */
247
248
if ($ request ->isPost ()) {
248
- $ data = $ this ->jsonSerializer ->unserialize ($ request ->getContent ());
249
+ $ data = $ request -> getContent () ? $ this ->jsonSerializer ->unserialize ($ request ->getContent ()) : [] ;
249
250
} elseif ($ request ->isGet ()) {
250
251
$ data = $ request ->getParams ();
251
252
$ data ['variables ' ] = isset ($ data ['variables ' ]) ?
Original file line number Diff line number Diff line change @@ -273,7 +273,7 @@ public function testDispatchWithOptions(): void
273
273
self ::assertEmpty ($ response ->getContent ());
274
274
}
275
275
276
- public function testDispatchWithoutQuery (): void
276
+ public function testDispatchWithGetWithoutQuery (): void
277
277
{
278
278
$ this ->request ->setPathInfo ('/graphql ' );
279
279
$ this ->request ->setMethod ('GET ' );
@@ -282,4 +282,32 @@ public function testDispatchWithoutQuery(): void
282
282
$ output = $ this ->jsonSerializer ->unserialize ($ response ->getContent ());
283
283
self ::assertNotEmpty ($ output ['errors ' ]);
284
284
}
285
+
286
+ public function testDispatchWithPostAndWrongContentType (): void
287
+ {
288
+ $ query = <<<QUERY
289
+ {
290
+ products(filter: {sku: {eq: "simple1"}}) {
291
+ items {
292
+ id
293
+ name
294
+ sku
295
+ }
296
+ }
297
+ }
298
+ QUERY ;
299
+ $ postData = [
300
+ 'query ' => $ query ,
301
+ 'variables ' => null ,
302
+ 'operationName ' => null
303
+ ];
304
+
305
+ $ this ->request ->setPathInfo ('/graphql ' );
306
+ $ this ->request ->setMethod ('POST ' );
307
+ $ this ->request ->setContent (json_encode ($ postData ));
308
+ $ response = $ this ->graphql ->dispatch ($ this ->request );
309
+ self ::assertEquals (400 , $ response ->getStatusCode ());
310
+ $ output = $ this ->jsonSerializer ->unserialize ($ response ->getContent ());
311
+ self ::assertNotEmpty ($ output ['errors ' ]);
312
+ }
285
313
}
You can’t perform that action at this time.
0 commit comments