-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from adri/feature/exception-mapping
Exceptions can be mapped to UserError and UserWarning
- Loading branch information
Showing
12 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the OverblogGraphQLBundle package. | ||
* | ||
* (c) Overblog <http://github.com/overblog/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Overblog\GraphQLBundle\Tests\Functional\Exception; | ||
|
||
use Overblog\GraphQLBundle\Tests\Functional\TestCase; | ||
|
||
/** | ||
* Class ConnectionTest. | ||
* | ||
* @see https://github.com/graphql/graphql-relay-js/blob/master/src/connection/__tests__/connection.js | ||
*/ | ||
class ExceptionTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
static::createAndBootKernel(['test_case' => 'exception']); | ||
} | ||
|
||
public function testExceptionIsMappedToAWarning() | ||
{ | ||
$query = <<<EOF | ||
query ExceptionQuery { | ||
test | ||
} | ||
EOF; | ||
|
||
$expectedData = [ | ||
'test' => null, | ||
]; | ||
|
||
$expectedErrors = [ | ||
[ | ||
'message' => 'Invalid argument exception', | ||
'locations' => [ | ||
[ | ||
'line' => 2, | ||
'column' => 5, | ||
] | ||
], | ||
], | ||
]; | ||
|
||
$this->assertGraphQL($query, $expectedData, $expectedErrors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the OverblogGraphQLBundle package. | ||
* | ||
* (c) Overblog <http://github.com/overblog/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Overblog\GraphQLBundle\Tests\Functional\app\Exception; | ||
|
||
class ExampleException | ||
{ | ||
public function throwException() | ||
{ | ||
throw new \InvalidArgumentException('Invalid argument exception'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
imports: | ||
- { resource: ../config.yml } | ||
- { resource: services.yml } | ||
|
||
parameters: | ||
overblog_graphql.type_class_namespace: "Overblog\\GraphQLBundle\\Exception\\__DEFINITIONS__" | ||
|
||
overblog_graphql: | ||
definitions: | ||
exceptions: | ||
errors: | ||
- "InvalidArgumentException" | ||
schema: | ||
query: Query | ||
mutation: ~ | ||
mappings: | ||
types: | ||
- | ||
type: yml | ||
dir: "%kernel.root_dir%/config/exception/mapping" |
8 changes: 8 additions & 0 deletions
8
Tests/Functional/app/config/exception/mapping/exception.types.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Query: | ||
type: object | ||
config: | ||
fields: | ||
test: | ||
type: "Boolean" | ||
resolve: "@=resolver('example_exception')" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
overblog_graphql.test.exception: | ||
class: Overblog\GraphQLBundle\Tests\Functional\app\Exception\ExampleException | ||
tags: | ||
- { name: "overblog_graphql.resolver", alias: "example_exception", method: "throwException" } |