Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Sudiev committed Oct 1, 2024
1 parent 6012450 commit dae8b0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Parameters/PrefetchDataParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private function computePrefetch(array $args, mixed $context, ResolveInfo $info,
$toPassPrefetchArgs = QueryField::paramsToArguments($this->fieldName, $this->parameters, null, $args, $context, $info, $this->resolver);

$resolvedValues = ($this->resolver)($sources, ...$toPassPrefetchArgs);

foreach ($sources as $source) {
// map results to each source to support old prefetch behavior
$prefetchBuffer->storeResult($source, $resolvedValues);
Expand Down
8 changes: 5 additions & 3 deletions src/QueryField.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct(
$callResolver = function (...$args) use ($originalResolver, $source, $resolver) {
$result = $resolver($source, ...$args);

return $this->unwrapReturnType($result, $originalResolver);
return $this->resolveWithPromise($result, $originalResolver);
};

// GraphQL allows deferring resolving the field's value using promises, i.e. they call the resolve
Expand All @@ -90,18 +90,20 @@ public function __construct(
parent::__construct($config);
}

private function unwrapReturnType(mixed $result, ResolverInterface $originalResolver): mixed
private function resolveWithPromise(mixed $result, ResolverInterface $originalResolver): mixed
{
if ($result instanceof SyncPromise) {
return $result->then(fn ($resolvedValue) => $this->unwrapReturnType($resolvedValue, $originalResolver));
return $result->then(fn ($resolvedValue) => $this->resolveWithPromise($resolvedValue, $originalResolver));
}

try {
$this->assertReturnType($result);
} catch (TypeMismatchRuntimeException $e) {
$e->addInfo($this->name, $originalResolver->toString());

throw $e;
}

return $result;
}

Expand Down

0 comments on commit dae8b0e

Please sign in to comment.