Skip to content

Commit

Permalink
Merge a774db4 into ac986bd
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Oct 16, 2019
2 parents ac986bd + a774db4 commit 1226b96
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
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

0 comments on commit 1226b96

Please sign in to comment.