-
Notifications
You must be signed in to change notification settings - Fork 0
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 #6 from x-graphql/revert-remove-schema-execution-d…
…elegator Revert remove schema execution delegator
- Loading branch information
Showing
4 changed files
with
85 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace XGraphQL\DelegateExecution; | ||
|
||
use GraphQL\Type\Schema; | ||
|
||
interface SchemaExecutionDelegatorInterface extends ExecutionDelegatorInterface | ||
{ | ||
/** | ||
* @return Schema used to delegate query to execute | ||
*/ | ||
public function getSchema(): Schema; | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace XGraphQL\DelegateExecution\Test; | ||
|
||
use GraphQL\Executor\ExecutionResult; | ||
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter; | ||
use GraphQL\Executor\Promise\Promise; | ||
use GraphQL\Language\Parser; | ||
use GraphQL\Type\Schema; | ||
use PHPUnit\Framework\TestCase; | ||
use XGraphQL\DelegateExecution\SchemaExecutionDelegator; | ||
|
||
class SchemaExecutionDelegatorTest extends TestCase | ||
{ | ||
use DummySchemaTrait; | ||
|
||
public function testConstructor(): void | ||
{ | ||
$schema = $this->createStub(Schema::class); | ||
$instance = new SchemaExecutionDelegator($schema); | ||
|
||
$this->assertInstanceOf(SchemaExecutionDelegator::class, $instance); | ||
$this->assertInstanceOf(SyncPromiseAdapter::class, $instance->getPromiseAdapter()); | ||
$this->assertEquals($schema, $instance->getSchema()); | ||
} | ||
|
||
public function testCanDelegateQuery() | ||
{ | ||
$schema = $this->createDummySchema(); | ||
$adapter = new SyncPromiseAdapter(); | ||
$instance = new SchemaExecutionDelegator($schema, $adapter); | ||
$operation = Parser::operationDefinition( | ||
<<<'GQL' | ||
query test($include: Boolean!) { | ||
a: dummy @include(if: $include) | ||
...b | ||
} | ||
GQL | ||
); | ||
$fragment = Parser::fragmentDefinition( | ||
<<<'GQL' | ||
fragment b on Query { | ||
b: dummy_error | ||
} | ||
GQL | ||
); | ||
|
||
$promise = $instance->delegate($schema, $operation, [$fragment], ['include' => true]); | ||
|
||
$this->assertInstanceOf(Promise::class, $promise); | ||
|
||
$result = $adapter->wait($promise); | ||
|
||
$this->assertInstanceOf(ExecutionResult::class, $result); | ||
$this->assertEquals(['a' => 'dummy', 'b' => null], $result->data); | ||
$this->assertCount(1, $result->errors); | ||
$this->assertEquals(['b'], $result->errors[0]->getPath()); | ||
$this->assertEquals('Dummy error', $result->errors[0]->getMessage()); | ||
} | ||
} |