Skip to content

Commit

Permalink
Merge pull request #14 from x-graphql/add-delegate-dependency
Browse files Browse the repository at this point in the history
Add delegate dependency
  • Loading branch information
vuongxuongminh authored Mar 12, 2024
2 parents 1ba6ce9 + a83669b commit 302ad85
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 172 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "x-graphql/delegate-execution",
"description": "Support to delegate execution of GraphQL schema",
"description": "Delegate GraphQL schema execution",
"type": "library",
"require-dev": {
"phpunit/phpunit": "^11.0",
Expand All @@ -21,6 +21,7 @@
"require": {
"php": ">=8.2",
"webonyx/graphql-php": "^15.9",
"x-graphql/delegate": "^0.1.0",
"x-graphql/utils": ">=0.1.0"
},
"config": {
Expand Down
3 changes: 2 additions & 1 deletion src/Execution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace XGraphQL\DelegateExecution;

use GraphQL\Type\Schema;
use XGraphQL\Delegate\DelegatorInterface;

final class Execution
{
public static function delegate(
Schema $schema,
ExecutionDelegatorInterface $delegator,
DelegatorInterface $delegator,
DelegatedErrorsReporterInterface $errorsReporter = null,
): void {
foreach (['query', 'mutation', 'subscription'] as $operation) {
Expand Down
30 changes: 0 additions & 30 deletions src/ExecutionDelegatorInterface.php

This file was deleted.

5 changes: 3 additions & 2 deletions src/RootFieldsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use GraphQL\Type\Definition\WrappingType;
use GraphQL\Type\Introspection;
use GraphQL\Type\Schema;
use XGraphQL\Delegate\DelegatorInterface;
use XGraphQL\DelegateExecution\Exception\LogicException;
use XGraphQL\DelegateExecution\Exception\RuntimeException;
use XGraphQL\Utils\SelectionSet;
Expand All @@ -28,7 +29,7 @@ final class RootFieldsResolver
private \WeakMap $delegatedPromises;

public function __construct(
private readonly ExecutionDelegatorInterface $delegator,
private readonly DelegatorInterface $delegator,
private readonly ?DelegatedErrorsReporterInterface $delegatedErrorsReporter = null,
) {
$this->delegatedPromises = new \WeakMap();
Expand Down Expand Up @@ -67,7 +68,7 @@ private function delegateToExecute(Schema $schema, OperationDefinitionNode $oper
SelectionSet::addTypename($delegateOperation->getSelectionSet());
SelectionSet::addTypenameToFragments($delegateFragments);

$promise = $this->delegator->delegate($schema, $delegateOperation, $delegateFragments, $variables);
$promise = $this->delegator->delegateToExecute($schema, $delegateOperation, $delegateFragments, $variables);
} catch (\Throwable $exception) {
$result = new ExecutionResult(
null,
Expand Down
52 changes: 0 additions & 52 deletions src/SchemaExecutionDelegator.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/SchemaExecutionDelegatorInterface.php

This file was deleted.

6 changes: 3 additions & 3 deletions tests/BadExecutionDelegator.php → tests/BadDelegator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use GraphQL\Executor\Promise\PromiseAdapter;
use GraphQL\Language\AST\OperationDefinitionNode;
use GraphQL\Type\Schema;
use XGraphQL\DelegateExecution\ExecutionDelegatorInterface;
use XGraphQL\Delegate\DelegatorInterface;

final readonly class BadExecutionDelegator implements ExecutionDelegatorInterface
final readonly class BadDelegator implements DelegatorInterface
{
public function delegate(Schema $executionSchema, OperationDefinitionNode $operation, array $fragments = [], array $variables = []): Promise
public function delegateToExecute(Schema $executionSchema, OperationDefinitionNode $operation, array $fragments = [], array $variables = []): Promise
{
throw new \RuntimeException('Bad execution delegator');
}
Expand Down
14 changes: 8 additions & 6 deletions tests/ExecutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Utils\BuildSchema;
use PHPUnit\Framework\TestCase;
use XGraphQL\Delegate\DelegatorInterface;
use XGraphQL\Delegate\SchemaDelegator;
use XGraphQL\DelegateExecution\DelegatedErrorsReporterInterface;
use XGraphQL\DelegateExecution\Execution;
use XGraphQL\DelegateExecution\ExecutionDelegatorInterface;
Expand All @@ -21,7 +23,7 @@ class ExecutionTest extends TestCase

public function testDelegateSetup(): void
{
$delegator = $this->createStub(ExecutionDelegatorInterface::class);
$delegator = $this->createStub(DelegatorInterface::class);
$schema = BuildSchema::build(
<<<'SDL'
type Query {
Expand All @@ -42,7 +44,7 @@ public function testDelegateSetup(): void
public function testExecution(): void
{
$delegateSchema = $this->createDummySchema();
$delegator = new SchemaExecutionDelegator($delegateSchema);
$delegator = new SchemaDelegator($delegateSchema);
$schema = BuildSchema::build(
<<<'SDL'
type Query {
Expand Down Expand Up @@ -90,7 +92,7 @@ public function testExecution(): void
public function testLimitAccessFieldOfDelegateSchema(): void
{
$delegateSchema = $this->createDummySchema();
$delegator = new SchemaExecutionDelegator($delegateSchema);
$delegator = new SchemaDelegator($delegateSchema);
$schema = BuildSchema::build(
<<<'SDL'
type Query {
Expand Down Expand Up @@ -118,7 +120,7 @@ public function testLimitAccessFieldOfDelegateSchema(): void
public function testSchemaConflictFieldDefinitionWithDelegateSchema(): void
{
$delegateSchema = $this->createDummySchema();
$delegator = new SchemaExecutionDelegator($delegateSchema);
$delegator = new SchemaDelegator($delegateSchema);
$schema = BuildSchema::build(
<<<'SDL'
type Query {
Expand All @@ -143,7 +145,7 @@ public function testSchemaConflictFieldDefinitionWithDelegateSchema(): void
public function testSchemaConflictAbstractTypeWithDelegateSchema(): void
{
$delegateSchema = $this->createDummySchema();
$delegator = new SchemaExecutionDelegator($delegateSchema);
$delegator = new SchemaDelegator($delegateSchema);
$schema = BuildSchema::build(
<<<'SDL'
type Query {
Expand Down Expand Up @@ -187,7 +189,7 @@ function (array $errors) use (&$delegatedErrors): void {
}
);

$delegator = new BadExecutionDelegator();
$delegator = new BadDelegator();
$schema = BuildSchema::build(
<<<'SDL'
type Query {
Expand Down
62 changes: 0 additions & 62 deletions tests/SchemaExecutionDelegatorTest.php

This file was deleted.

0 comments on commit 302ad85

Please sign in to comment.