mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Revamping GraphQL facade methods
This commit is contained in:
parent
b56083b7de
commit
4634f214ea
159
src/GraphQL.php
159
src/GraphQL.php
@ -11,6 +11,7 @@ use GraphQL\Language\Parser;
|
|||||||
use GraphQL\Language\Source;
|
use GraphQL\Language\Source;
|
||||||
use GraphQL\Executor\Promise\PromiseAdapter;
|
use GraphQL\Executor\Promise\PromiseAdapter;
|
||||||
use GraphQL\Type\Definition\Directive;
|
use GraphQL\Type\Definition\Directive;
|
||||||
|
use GraphQL\Type\Definition\Type;
|
||||||
use GraphQL\Validator\DocumentValidator;
|
use GraphQL\Validator\DocumentValidator;
|
||||||
use GraphQL\Validator\Rules\QueryComplexity;
|
use GraphQL\Validator\Rules\QueryComplexity;
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ class GraphQL
|
|||||||
* fieldResolver:
|
* fieldResolver:
|
||||||
* A resolver function to use when one is not provided by the schema.
|
* A resolver function to use when one is not provided by the schema.
|
||||||
* If not provided, the default field resolver is used (which looks for a
|
* If not provided, the default field resolver is used (which looks for a
|
||||||
* value or method on the source value with the field's name).
|
* value on the source value with the field's name).
|
||||||
* validationRules:
|
* validationRules:
|
||||||
* A set of rules for query validation step. Default value is all available rules.
|
* A set of rules for query validation step. Default value is all available rules.
|
||||||
* Empty array would allow to skip query validation (may be convenient for persisted
|
* Empty array would allow to skip query validation (may be convenient for persisted
|
||||||
@ -51,57 +52,6 @@ class GraphQL
|
|||||||
* @param \GraphQL\Type\Schema $schema
|
* @param \GraphQL\Type\Schema $schema
|
||||||
* @param string|DocumentNode $source
|
* @param string|DocumentNode $source
|
||||||
* @param mixed $rootValue
|
* @param mixed $rootValue
|
||||||
* @param array $contextValue
|
|
||||||
* @param array|null $variableValues
|
|
||||||
* @param string|null $operationName
|
|
||||||
* @param callable $fieldResolver
|
|
||||||
* @param array $validationRules
|
|
||||||
* @param PromiseAdapter $promiseAdapter
|
|
||||||
*
|
|
||||||
* @return Promise|array
|
|
||||||
*/
|
|
||||||
public static function execute(
|
|
||||||
\GraphQL\Type\Schema $schema,
|
|
||||||
$source,
|
|
||||||
$rootValue = null,
|
|
||||||
$contextValue = null,
|
|
||||||
$variableValues = null,
|
|
||||||
$operationName = null,
|
|
||||||
callable $fieldResolver = null,
|
|
||||||
array $validationRules = null,
|
|
||||||
PromiseAdapter $promiseAdapter = null
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$result = self::executeAndReturnResult(
|
|
||||||
$schema,
|
|
||||||
$source,
|
|
||||||
$rootValue,
|
|
||||||
$contextValue,
|
|
||||||
$variableValues,
|
|
||||||
$operationName,
|
|
||||||
$fieldResolver,
|
|
||||||
$validationRules,
|
|
||||||
$promiseAdapter
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($result instanceof ExecutionResult) {
|
|
||||||
return $result->toArray();
|
|
||||||
}
|
|
||||||
if ($result instanceof Promise) {
|
|
||||||
return $result->then(function(ExecutionResult $executionResult) {
|
|
||||||
return $executionResult->toArray();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw new InvariantViolation("Unexpected execution result");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as `execute`, but returns instance of ExecutionResult instead of array,
|
|
||||||
* which can be used for custom error formatting or adding extensions to response
|
|
||||||
*
|
|
||||||
* @param \GraphQL\Type\Schema $schema
|
|
||||||
* @param string|DocumentNode $source
|
|
||||||
* @param mixed $rootValue
|
|
||||||
* @param mixed $contextValue
|
* @param mixed $contextValue
|
||||||
* @param array|null $variableValues
|
* @param array|null $variableValues
|
||||||
* @param string|null $operationName
|
* @param string|null $operationName
|
||||||
@ -111,7 +61,7 @@ class GraphQL
|
|||||||
*
|
*
|
||||||
* @return ExecutionResult|Promise
|
* @return ExecutionResult|Promise
|
||||||
*/
|
*/
|
||||||
public static function executeAndReturnResult(
|
public static function executeQuery(
|
||||||
\GraphQL\Type\Schema $schema,
|
\GraphQL\Type\Schema $schema,
|
||||||
$source,
|
$source,
|
||||||
$rootValue = null,
|
$rootValue = null,
|
||||||
@ -156,13 +106,114 @@ class GraphQL
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @deprecated Use executeQuery()->toArray() instead
|
||||||
|
*
|
||||||
|
* @param \GraphQL\Type\Schema $schema
|
||||||
|
* @param string|DocumentNode $source
|
||||||
|
* @param mixed $rootValue
|
||||||
|
* @param mixed $contextValue
|
||||||
|
* @param array|null $variableValues
|
||||||
|
* @param string|null $operationName
|
||||||
|
* @param callable $fieldResolver
|
||||||
|
* @param array $validationRules
|
||||||
|
* @param PromiseAdapter $promiseAdapter
|
||||||
|
* @return Promise|array
|
||||||
|
*/
|
||||||
|
public static function execute(
|
||||||
|
\GraphQL\Type\Schema $schema,
|
||||||
|
$source,
|
||||||
|
$rootValue = null,
|
||||||
|
$contextValue = null,
|
||||||
|
$variableValues = null,
|
||||||
|
$operationName = null,
|
||||||
|
callable $fieldResolver = null,
|
||||||
|
array $validationRules = null,
|
||||||
|
PromiseAdapter $promiseAdapter = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$result = self::executeQuery(
|
||||||
|
$schema,
|
||||||
|
$source,
|
||||||
|
$rootValue,
|
||||||
|
$contextValue,
|
||||||
|
$variableValues,
|
||||||
|
$operationName,
|
||||||
|
$fieldResolver,
|
||||||
|
$validationRules,
|
||||||
|
$promiseAdapter
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result instanceof ExecutionResult) {
|
||||||
|
return $result->toArray();
|
||||||
|
}
|
||||||
|
if ($result instanceof Promise) {
|
||||||
|
return $result->then(function(ExecutionResult $executionResult) {
|
||||||
|
return $executionResult->toArray();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw new InvariantViolation("Unexpected execution result");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated renamed to executeQuery()
|
||||||
|
*
|
||||||
|
* @param \GraphQL\Type\Schema $schema
|
||||||
|
* @param string|DocumentNode $source
|
||||||
|
* @param mixed $rootValue
|
||||||
|
* @param mixed $contextValue
|
||||||
|
* @param array|null $variableValues
|
||||||
|
* @param string|null $operationName
|
||||||
|
* @param callable $fieldResolver
|
||||||
|
* @param array $validationRules
|
||||||
|
* @param PromiseAdapter $promiseAdapter
|
||||||
|
*
|
||||||
|
* @return ExecutionResult|Promise
|
||||||
|
*/
|
||||||
|
public static function executeAndReturnResult(
|
||||||
|
\GraphQL\Type\Schema $schema,
|
||||||
|
$source,
|
||||||
|
$rootValue = null,
|
||||||
|
$contextValue = null,
|
||||||
|
$variableValues = null,
|
||||||
|
$operationName = null,
|
||||||
|
callable $fieldResolver = null,
|
||||||
|
array $validationRules = null,
|
||||||
|
PromiseAdapter $promiseAdapter = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return self::executeQuery(
|
||||||
|
$schema,
|
||||||
|
$source,
|
||||||
|
$rootValue,
|
||||||
|
$contextValue,
|
||||||
|
$variableValues,
|
||||||
|
$operationName,
|
||||||
|
$fieldResolver,
|
||||||
|
$validationRules,
|
||||||
|
$promiseAdapter
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns directives defined in GraphQL spec
|
||||||
|
*
|
||||||
|
* @return Directive[]
|
||||||
*/
|
*/
|
||||||
public static function getInternalDirectives()
|
public static function getInternalDirectives()
|
||||||
{
|
{
|
||||||
return array_values(Directive::getInternalDirectives());
|
return array_values(Directive::getInternalDirectives());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns types defined in GraphQL spec
|
||||||
|
*
|
||||||
|
* @return Type[]
|
||||||
|
*/
|
||||||
|
public static function getInternalTypes()
|
||||||
|
{
|
||||||
|
return Type::getInternalTypes();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param callable $fn
|
* @param callable $fn
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user