Skip to content

Commit a774db4

Browse files
committed
Adds support for the new error handling mechanism in the Symfony bundle.
1 parent b462023 commit a774db4

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Resources/config/container/graphqlite.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
<call method="setSchema">
5858
<argument type="service" id="TheCodingMachine\GraphQLite\Schema"/>
5959
</call>
60+
<call method="setErrorFormatter">
61+
<argument type="collection">
62+
<argument>\TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler</argument>
63+
<argument>errorFormatter</argument>
64+
</argument>
65+
</call>
66+
<call method="setErrorsHandler">
67+
<argument type="collection">
68+
<argument>\TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler</argument>
69+
<argument>errorHandler</argument>
70+
</argument>
71+
</call>
6072
</service>
6173

6274
<service id="TheCodingMachine\GraphQLite\Mappers\StaticTypeMapper">

Tests/Fixtures/Controller/TestGraphqlController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Entities\Product;
1515
use TheCodingMachine\GraphQLite\Annotations\Mutation;
1616
use TheCodingMachine\GraphQLite\Annotations\Query;
17+
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
18+
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;
1719

1820
class TestGraphqlController
1921
{
@@ -71,6 +73,17 @@ public function triggerException(int $code = 0): string
7173
throw new MyException('Boom', $code);
7274
}
7375

76+
/**
77+
* @Query()
78+
* @return string
79+
*/
80+
public function triggerAggregateException(): string
81+
{
82+
$exception1 = new GraphQLException('foo', 401);
83+
$exception2 = new GraphQLException('bar', 404, null, 'MyCat', ['field' => 'baz']);
84+
throw new GraphQLAggregateException([$exception1, $exception2]);
85+
}
86+
7487
/**
7588
* @Query()
7689
* @Logged()

Tests/FunctionalTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ public function testErrors(): void
137137
$this->assertSame(404, $response->getStatusCode(), $response->getContent());
138138
}
139139

140+
public function testExceptionHandler(): void
141+
{
142+
$kernel = new GraphqliteTestingKernel();
143+
$kernel->boot();
144+
145+
$request = Request::create('/graphql', 'GET', ['query' => '
146+
{
147+
triggerAggregateException
148+
}']);
149+
150+
$response = $kernel->handle($request);
151+
152+
$this->assertSame(404, $response->getStatusCode());
153+
154+
$result = json_decode($response->getContent(), true);
155+
var_dump($result);
156+
157+
//$this->assertSame('Cannot query field "me" on type "Query".', $result['errors'][0]['message']);
158+
159+
}
160+
140161
public function testLoggedMiddleware(): void
141162
{
142163
$kernel = new GraphqliteTestingKernel();

0 commit comments

Comments
 (0)