Skip to content

Adds support for the new error handling mechanism in the Symfony bundle. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Resources/config/container/graphqlite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
<call method="setSchema">
<argument type="service" id="TheCodingMachine\GraphQLite\Schema"/>
</call>
<call method="setErrorFormatter">
<argument type="collection">
<argument>\TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler</argument>
<argument>errorFormatter</argument>
</argument>
</call>
<call method="setErrorsHandler">
<argument type="collection">
<argument>\TheCodingMachine\GraphQLite\Exceptions\WebonyxErrorHandler</argument>
<argument>errorHandler</argument>
</argument>
</call>
</service>

<service id="TheCodingMachine\GraphQLite\Mappers\StaticTypeMapper">
Expand Down
13 changes: 13 additions & 0 deletions Tests/Fixtures/Controller/TestGraphqlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\Entities\Product;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
use TheCodingMachine\GraphQLite\Exceptions\GraphQLException;

class TestGraphqlController
{
Expand Down Expand Up @@ -71,6 +73,17 @@ public function triggerException(int $code = 0): string
throw new MyException('Boom', $code);
}

/**
* @Query()
* @return string
*/
public function triggerAggregateException(): string
{
$exception1 = new GraphQLException('foo', 401);
$exception2 = new GraphQLException('bar', 404, null, 'MyCat', ['field' => 'baz']);
throw new GraphQLAggregateException([$exception1, $exception2]);
}

/**
* @Query()
* @Logged()
Expand Down
21 changes: 21 additions & 0 deletions Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ public function testErrors(): void
$this->assertSame(404, $response->getStatusCode(), $response->getContent());
}

public function testExceptionHandler(): void
{
$kernel = new GraphqliteTestingKernel();
$kernel->boot();

$request = Request::create('/graphql', 'GET', ['query' => '
{
triggerAggregateException
}']);

$response = $kernel->handle($request);

$this->assertSame(404, $response->getStatusCode());

$result = json_decode($response->getContent(), true);
var_dump($result);

//$this->assertSame('Cannot query field "me" on type "Query".', $result['errors'][0]['message']);

}

public function testLoggedMiddleware(): void
{
$kernel = new GraphqliteTestingKernel();
Expand Down