Skip to content

Commit

Permalink
update error location handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joonlabs committed Sep 15, 2022
1 parent a6db03d commit 11c85ec
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Errors/GraphQLError.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GraphQLError extends Exception
* @param array|null $path
* @param array|null $customExtensions
*/
public function __construct(string $message = "", array $node = null, array $path = null, array $customExtensions=null)
public function __construct(string $message = "", array $node = null, array $path = null, array $customExtensions = null)
{
parent::__construct($message);
$this->node = $node;
Expand All @@ -38,7 +38,15 @@ public function __construct(string $message = "", array $node = null, array $pat
*/
public function getLocations(): ?array
{
return [$this->node["loc"]] ?? null;
// get location of error
$location = $this->node["loc"] ?? null;

// return null if location is null
if ($location === null)
return null;

// return location
return [$location];
}

/**
Expand All @@ -60,7 +68,7 @@ public function getSimplifiedPath(): ?array
{
$simplifiedPath = [];
$currentPathField = $this->path;
while($currentPathField !== null){
while ($currentPathField !== null) {
$simplifiedPath[] = $currentPathField[0];
$currentPathField = $currentPathField[2];
}
Expand Down

0 comments on commit 11c85ec

Please sign in to comment.