-
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create field args mapper and cache args resolution
- Loading branch information
Showing
10 changed files
with
177 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,18 @@ | |
use GraphQL\Executor\Promise\Promise; | ||
use GraphQL\Executor\Promise\PromiseAdapter; | ||
use GraphQL\Language\AST\DocumentNode; | ||
use GraphQL\Language\AST\FieldNode; | ||
use GraphQL\Type\Definition\FieldDefinition; | ||
use GraphQL\Type\Definition\ResolveInfo; | ||
use GraphQL\Type\Schema; | ||
use GraphQL\Utils\Utils; | ||
|
||
/** | ||
* Implements the "Evaluating requests" section of the GraphQL specification. | ||
* | ||
* @phpstan-type ArgsMapper callable(array<string, mixed>, FieldDefinition, FieldNode, mixed): mixed | ||
* @phpstan-type FieldResolver callable(mixed, array<string, mixed>, mixed, ResolveInfo): mixed | ||
* @phpstan-type ImplementationFactory callable(PromiseAdapter, Schema, DocumentNode, mixed, mixed, array<mixed>, ?string, callable): ExecutorImplementation | ||
* @phpstan-type ImplementationFactory callable(PromiseAdapter, Schema, DocumentNode, mixed, mixed, array<mixed>, ?string, callable, callable): ExecutorImplementation | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
andrew-demb
Contributor
|
||
* | ||
* @see \GraphQL\Tests\Executor\ExecutorTest | ||
*/ | ||
|
@@ -28,6 +31,13 @@ class Executor | |
*/ | ||
private static $defaultFieldResolver = [self::class, 'defaultFieldResolver']; | ||
|
||
/** | ||
* @var callable | ||
* | ||
* @phpstan-var ArgsMapper | ||
*/ | ||
private static $defaultArgsMapper = [self::class, 'defaultArgsMapper']; | ||
|
||
private static ?PromiseAdapter $defaultPromiseAdapter; | ||
|
||
/** | ||
|
@@ -53,6 +63,12 @@ public static function setDefaultFieldResolver(callable $fieldResolver): void | |
self::$defaultFieldResolver = $fieldResolver; | ||
} | ||
|
||
/** @phpstan-param ArgsMapper $argsMapper */ | ||
public static function setDefaultArgsMapper(callable $argsMapper): void | ||
{ | ||
self::$defaultArgsMapper = $argsMapper; | ||
} | ||
|
||
public static function getPromiseAdapter(): PromiseAdapter | ||
{ | ||
return self::$defaultPromiseAdapter ??= new SyncPromiseAdapter(); | ||
|
@@ -132,6 +148,7 @@ public static function execute( | |
* @param array<string, mixed>|null $variableValues | ||
* | ||
* @phpstan-param FieldResolver|null $fieldResolver | ||
* @phpstan-param ArgsMapper|null $argsMapper | ||
* | ||
* @api | ||
*/ | ||
|
@@ -143,7 +160,8 @@ public static function promiseToExecute( | |
$contextValue = null, | ||
?array $variableValues = null, | ||
?string $operationName = null, | ||
?callable $fieldResolver = null | ||
?callable $fieldResolver = null, | ||
?callable $argsMapper = null | ||
): Promise { | ||
$executor = (self::$implementationFactory)( | ||
$promiseAdapter, | ||
|
@@ -153,7 +171,8 @@ public static function promiseToExecute( | |
$contextValue, | ||
$variableValues ?? [], | ||
$operationName, | ||
$fieldResolver ?? self::$defaultFieldResolver | ||
$fieldResolver ?? self::$defaultFieldResolver, | ||
$argsMapper ?? self::$defaultArgsMapper, | ||
); | ||
|
||
return $executor->doExecute(); | ||
|
@@ -179,4 +198,16 @@ public static function defaultFieldResolver($objectLikeValue, array $args, $cont | |
? $property($objectLikeValue, $args, $contextValue, $info) | ||
: $property; | ||
} | ||
|
||
/** | ||
* @template T of array<string, mixed> | ||
* | ||
* @param T $args | ||
* | ||
* @return T | ||
*/ | ||
public static function defaultArgsMapper(array $args): array | ||
{ | ||
return $args; | ||
} | ||
} |
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
Oops, something went wrong.
Adding the required parameter is a BC break, isn't it?
Our tests are broken after upgrading to the
15.16
@Warxcell @spawnia are you OK with PR that tries to make this parameter optional?