Skip to content

Commit 29323d9

Browse files
committed
Merge branch '5.x' into mp-release-6
# Conflicts: # CHANGELOG.md
2 parents 1e36e0a + 4821c2d commit 29323d9

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
CHANGELOG
22
=========
33

4-
[Next release](https://github.com/rebing/graphql-laravel/compare/6.0.0-rc1...master)
4+
[Next release](https://github.com/rebing/graphql-laravel/compare/6.0.0...master)
55
--------------
66

7+
2020-11-26, 6.0.0
8+
-----------------
9+
### Fixed
10+
- Implemented generation of a SyntaxError instead of an hard Exception for empty single/batch queries [\#685 / plivius](https://github.com/rebing/graphql-laravel/pull/685)
11+
712
2020-11-13, 6.0.0-rc1
813
---------------------
9-
1014
## Breaking changes
1115
- Upgrade to webonyx/graphql-php 14.0.0 [\#645 / mfn](https://github.com/rebing/graphql-laravel/pull/645)
1216
- Remove support for Laravel < 6.0 [\#651 / mfn](https://github.com/rebing/graphql-laravel/pull/651)
@@ -15,9 +19,13 @@ CHANGELOG
1519
### Added
1620
- Support for Laravel 8 [\#672 / mfn](https://github.com/rebing/graphql-laravel/pull/672)
1721

22+
2020-11-26, 5.1.5
23+
-----------------
24+
### Fixed
25+
- Implemented generation of a SyntaxError instead of an hard Exception for empty single/batch queries [\#685 / plivius](https://github.com/rebing/graphql-laravel/pull/685)
26+
1827
2020-11-16, 5.1.5-rc1
1928
---------------------
20-
2129
### Added
2230
- Support for PHP 8 [\#686 / mfn](https://github.com/rebing/graphql-laravel/pull/686)
2331

src/GraphQLController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function query(Request $request, string $schema = null): JsonResponse
4545

4646
// Complete each query in order
4747
foreach ($inputs as $input) {
48-
$completedQueries[] = $this->executeQuery($schema, $input);
48+
$completedQueries[] = $this->executeQuery($schema, $input ?: []);
4949
}
5050

5151
$data = $isBatch ? $completedQueries : $completedQueries[0];
@@ -58,7 +58,7 @@ public function query(Request $request, string $schema = null): JsonResponse
5858

5959
protected function executeQuery(string $schema, array $input): array
6060
{
61-
$query = $input['query'];
61+
$query = $input['query'] ?? '';
6262

6363
$paramsKey = config('graphql.params_key', 'variables');
6464
$params = $input[$paramsKey] ?? null;

tests/Database/EmptyQueryTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rebing\GraphQL\Tests\Database;
6+
7+
use Rebing\GraphQL\Tests\TestCaseDatabase;
8+
9+
class EmptyQueryTest extends TestCaseDatabase
10+
{
11+
/**
12+
* @dataProvider dataForEmptyQuery
13+
* @param array<mixed> $parameters
14+
* @param bool $isBatchRequest
15+
* @param bool $expectErrors
16+
*/
17+
public function testEmptyQuery(array $parameters, bool $isBatchRequest, bool $expectErrors): void
18+
{
19+
$response = $this->call('GET', '/graphql', $parameters);
20+
21+
$this->assertSame(200, $response->getStatusCode());
22+
$results = $isBatchRequest ? $response->getData(true) : [$response->getData(true)];
23+
24+
foreach ($results as $result) {
25+
if ($expectErrors) {
26+
$this->assertCount(1, $result['errors']);
27+
$this->assertSame('Syntax Error: Unexpected <EOF>', $result['errors'][0]['message']);
28+
$this->assertSame('graphql', $result['errors'][0]['extensions']['category']);
29+
} else {
30+
$this->assertArrayNotHasKey('errors', $result);
31+
}
32+
}
33+
}
34+
35+
/**
36+
* @return array<mixed>
37+
*/
38+
public function dataForEmptyQuery(): array
39+
{
40+
return [
41+
// completely empty request
42+
[
43+
'parameters' => [],
44+
'isBatchRequest' => false,
45+
'expectErrors' => false,
46+
],
47+
// single request with an empty query parameter
48+
[
49+
'parameters' => ['query' => null],
50+
'isBatchRequest' => false,
51+
'expectErrors' => true,
52+
],
53+
[
54+
'parameters' => ['query' => ''],
55+
'isBatchRequest' => false,
56+
'expectErrors' => true,
57+
],
58+
[
59+
'parameters' => ['query' => ' '],
60+
'isBatchRequest' => false,
61+
'expectErrors' => true,
62+
],
63+
[
64+
'parameters' => ['query' => '#'],
65+
'isBatchRequest' => false,
66+
'expectErrors' => true,
67+
],
68+
// batch request with one completely empty batch, and batches with an empty query parameter
69+
[
70+
'parameters' => [[], ['query' => null], ['query' => ''], ['query' => ' '], ['query' => '#']],
71+
'isBatchRequest' => true,
72+
'expectErrors' => true,
73+
],
74+
];
75+
}
76+
}

0 commit comments

Comments
 (0)