Skip to content

Commit

Permalink
Remove redundant lines in ReferenceExecutor
Browse files Browse the repository at this point in the history
Somehow this was added in webonyx#1548 but I fail to see why.

Let's remove it.

This might be the cause for the performance degradation reported in webonyx#1548.

Add property `unaliasedPath` to `ResolveInfo`
  • Loading branch information
ruudk authored and simPod committed Jun 11, 2024
1 parent 6860876 commit c807d5c
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 50 deletions.
33 changes: 28 additions & 5 deletions docs/class-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Passed as 4th argument to every field resolver. See [docs on field resolving (da

@phpstan-import-type QueryPlanOptions from QueryPlan

@phpstan-type Path array<int, string|int>
@phpstan-type Path list<string|int>

### GraphQL\Type\Definition\ResolveInfo Props

Expand Down Expand Up @@ -351,16 +351,27 @@ public $fieldNodes;
public $parentType;

/**
* Path to this field from the very root value.
* Path to this field from the very root value. When fields are aliased, the path includes aliases.
*
* @api
*
* @var array<int, string|int>
* @var list<string|int>
*
* @phpstan-var Path
*/
public $path;

/**
* Path to this field from the very root value. This will never include aliases.
*
* @api
*
* @var list<string|int>
*
* @phpstan-var Path
*/
public $unaliasedPath;

/**
* Instance of a schema used for execution.
*
Expand Down Expand Up @@ -1730,15 +1741,27 @@ function getLocations(): array
```php
/**
* Returns an array describing the path from the root value to the field which produced this error.
* Only included for execution errors.
* Only included for execution errors. When fields are aliased, the path includes aliases.
*
* @return array<int, int|string>|null
* @return list<int|string>|null
*
* @api
*/
function getPath(): ?array
```

```php
/**
* Returns an array describing the path from the root value to the field which produced this error.
* Only included for execution errors. This will never include aliases.
*
* @return list<int|string>|null
*
* @api
*/
function getUnaliasedPath(): ?array
```

## GraphQL\Error\Warning

Encapsulates warnings produced by the library.
Expand Down
45 changes: 37 additions & 8 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ class Error extends \Exception implements \JsonSerializable, ClientAware, Provid
/**
* An array describing the JSON-path into the execution response which
* corresponds to this error. Only included for errors during execution.
* When fields are aliased, the path includes aliases.
*
* @var array<int, int|string>|null
* @var list<int|string>|null
*/
public ?array $path;

/**
* An array describing the JSON-path into the execution response which
* corresponds to this error. Only included for errors during execution.
* This will never include aliases.
*
* @var list<int|string>|null
*/
public ?array $unaliasedPath;

/**
* An array of GraphQL AST Nodes corresponding to this error.
*
Expand All @@ -65,8 +75,9 @@ class Error extends \Exception implements \JsonSerializable, ClientAware, Provid
/**
* @param iterable<array-key, Node|null>|Node|null $nodes
* @param array<int, int>|null $positions
* @param array<int, int|string>|null $path
* @param list<int|string>|null $path
* @param array<string, mixed>|null $extensions
* @param list<int|string>|null $unaliasedPath
*/
public function __construct(
string $message = '',
Expand All @@ -75,7 +86,8 @@ public function __construct(
?array $positions = null,
?array $path = null,
?\Throwable $previous = null,
?array $extensions = null
?array $extensions = null,
?array $unaliasedPath = null
) {
parent::__construct($message, 0, $previous);

Expand All @@ -93,6 +105,7 @@ public function __construct(
$this->source = $source;
$this->positions = $positions;
$this->path = $path;
$this->unaliasedPath = $unaliasedPath;

if (\is_array($extensions) && $extensions !== []) {
$this->extensions = $extensions;
Expand All @@ -114,9 +127,10 @@ public function __construct(
*
* @param mixed $error
* @param iterable<Node>|Node|null $nodes
* @param array<int, int|string>|null $path
* @param list<int|string>|null $path
* @param list<int|string>|null $unaliasedPath
*/
public static function createLocatedError($error, $nodes = null, ?array $path = null): Error
public static function createLocatedError($error, $nodes = null, ?array $path = null, ?array $unaliasedPath = null): Error
{
if ($error instanceof self) {
if ($error->isLocated()) {
Expand All @@ -125,6 +139,7 @@ public static function createLocatedError($error, $nodes = null, ?array $path =

$nodes ??= $error->getNodes();
$path ??= $error->getPath();
$unaliasedPath ??= $error->getUnaliasedPath();
}

$source = null;
Expand Down Expand Up @@ -159,7 +174,8 @@ public static function createLocatedError($error, $nodes = null, ?array $path =
$positions,
$path,
$originalError,
$extensions
$extensions,
$unaliasedPath
);
}

Expand Down Expand Up @@ -251,9 +267,9 @@ public function getNodes(): ?array

/**
* Returns an array describing the path from the root value to the field which produced this error.
* Only included for execution errors.
* Only included for execution errors. When fields are aliased, the path includes aliases.
*
* @return array<int, int|string>|null
* @return list<int|string>|null
*
* @api
*/
Expand All @@ -262,6 +278,19 @@ public function getPath(): ?array
return $this->path;
}

/**
* Returns an array describing the path from the root value to the field which produced this error.
* Only included for execution errors. This will never include aliases.
*
* @return list<int|string>|null
*
* @api
*/
public function getUnaliasedPath(): ?array
{
return $this->unaliasedPath;
}

/** @return array<string, mixed>|null */
public function getExtensions(): ?array
{
Expand Down
Loading

0 comments on commit c807d5c

Please sign in to comment.