Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Merge 4d6b93f into c6ed3ed
Browse files Browse the repository at this point in the history
  • Loading branch information
crisu83 committed Jul 30, 2019
2 parents c6ed3ed + 4d6b93f commit 3380138
Show file tree
Hide file tree
Showing 26 changed files with 1,935 additions and 1,747 deletions.
6 changes: 5 additions & 1 deletion src/Error/GraphQLException.php
Expand Up @@ -214,10 +214,14 @@ public function toArray(): array
{
$result = [
'message' => $this->message,
// TODO: Do not include `locations` if `null` (similar to `path` and `extensions`).
'locations' => $this->getLocationsAsArray(),
'path' => $this->path,
];

if (null !== $this->path) {
$result['path'] = $this->path;
}

if (null !== $this->extensions) {
$result['extensions'] = $this->extensions;
}
Expand Down
17 changes: 7 additions & 10 deletions src/Execution/Execution.php
Expand Up @@ -48,10 +48,9 @@ public function execute(
return resolve(new ExecutionResult(null, [$error]));
}

$valuesResolver = new ValuesResolver();
$fieldCollector = new FieldCollector($context, $valuesResolver);
$fieldCollector = new FieldCollector($context);

$data = $this->executeOperation($operationName, $context, $fieldCollector, $valuesResolver);
$data = $this->executeOperation($operationName, $context, $fieldCollector);

if ($data instanceof PromiseInterface) {
return $data->then(function ($resolvedData) use ($context) {
Expand All @@ -72,18 +71,16 @@ public function execute(
* @param null|string $operationName
* @param ExecutionContext $context
* @param FieldCollector $fieldCollector
* @param ValuesResolver $valuesResolver
* @return array|mixed|null|PromiseInterface
*/
protected function executeOperation(
?string $operationName,
ExecutionContext $context,
FieldCollector $fieldCollector,
ValuesResolver $valuesResolver
FieldCollector $fieldCollector
) {
$strategy = $operationName === 'mutation'
? new SerialExecutionStrategy($context, $fieldCollector, $valuesResolver)
: new ParallelExecutionStrategy($context, $fieldCollector, $valuesResolver);
? new SerialExecutionStrategy($context, $fieldCollector)
: new ParallelExecutionStrategy($context, $fieldCollector);

$result = null;

Expand All @@ -100,7 +97,7 @@ protected function executeOperation(
if ($result instanceof PromiseInterface) {
return $result->then(null, function (ExecutionException $exception) use ($context) {
$context->addError($exception);
return \React\Promise\resolve(null);
return resolve(null);
});
}

Expand Down Expand Up @@ -161,7 +158,7 @@ protected function createContext(
throw new ExecutionException('Must provide an operation.');
}

$coercedVariableValues = (new ValuesResolver())->coerceVariableValues(
$coercedVariableValues = ValuesResolver::coerceVariableValues(
$schema,
$operation->getVariableDefinitions(),
$rawVariableValues
Expand Down
10 changes: 1 addition & 9 deletions src/Execution/Strategy/AbstractExecutionStrategy.php
Expand Up @@ -42,11 +42,6 @@ abstract class AbstractExecutionStrategy implements ExecutionStrategyInterface
*/
protected $fieldCollector;

/**
* @var ValuesResolver
*/
protected $valuesResolver;

/**
* @var callable
*/
Expand All @@ -73,20 +68,17 @@ abstract public function executeFields(ObjectType $parentType, $rootValue, array
*
* @param ExecutionContext $context
* @param FieldCollector $fieldCollector
* @param ValuesResolver $valueResolver
* @param callable|null $typeResolverCallback
* @param callable|null $fieldResolverCallback
*/
public function __construct(
ExecutionContext $context,
FieldCollector $fieldCollector,
ValuesResolver $valueResolver,
?callable $typeResolverCallback = null,
?callable $fieldResolverCallback = null
) {
$this->context = $context;
$this->fieldCollector = $fieldCollector;
$this->valuesResolver = $valueResolver;
$this->typeResolverCallback = $typeResolverCallback ?? [$this, 'defaultTypeResolver'];
$this->fieldResolverCallback = $fieldResolverCallback ?? [$this, 'defaultFieldResolver'];
}
Expand Down Expand Up @@ -245,7 +237,7 @@ protected function resolveFieldValueOrError(
// variables scope to fulfill any variable references.
$result = $resolveCallback(
$rootValue,
$this->valuesResolver->coerceArgumentValues($field, $fieldNode, $context->getVariableValues()),
ValuesResolver::coerceArgumentValues($field, $fieldNode, $context->getVariableValues()),
$context->getContextValue(),
$info
);
Expand Down
13 changes: 3 additions & 10 deletions src/Execution/Strategy/FieldCollector.php
Expand Up @@ -36,22 +36,15 @@ class FieldCollector
*/
protected $includeDirective;

/**
* @var ValuesResolver
*/
protected $valuesResolver;

/**
* FieldCollector constructor.
* @param ExecutionContext $context
* @param ValuesResolver $valuesResolver
*/
public function __construct(ExecutionContext $context, ValuesResolver $valuesResolver)
public function __construct(ExecutionContext $context)
{
$this->context = $context;
$this->skipDirective = SkipDirective();
$this->includeDirective = IncludeDirective();
$this->valuesResolver = $valuesResolver;
}

/**
Expand Down Expand Up @@ -131,13 +124,13 @@ protected function shouldIncludeNode(NodeInterface $node): bool
{
$contextVariables = $this->context->getVariableValues();

$skip = $this->valuesResolver->coerceDirectiveValues($this->skipDirective, $node, $contextVariables);
$skip = ValuesResolver::coerceDirectiveValues($this->skipDirective, $node, $contextVariables);

if ($skip && $skip['if'] === true) {
return false;
}

$include = $this->valuesResolver->coerceDirectiveValues($this->includeDirective, $node, $contextVariables);
$include = ValuesResolver::coerceDirectiveValues($this->includeDirective, $node, $contextVariables);

if ($include && $include['if'] === false) {
return false;
Expand Down

0 comments on commit 3380138

Please sign in to comment.