Skip to content

Commit 11c85ec

Browse files
committed
update error location handling
1 parent a6db03d commit 11c85ec

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Errors/GraphQLError.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GraphQLError extends Exception
2323
* @param array|null $path
2424
* @param array|null $customExtensions
2525
*/
26-
public function __construct(string $message = "", array $node = null, array $path = null, array $customExtensions=null)
26+
public function __construct(string $message = "", array $node = null, array $path = null, array $customExtensions = null)
2727
{
2828
parent::__construct($message);
2929
$this->node = $node;
@@ -38,7 +38,15 @@ public function __construct(string $message = "", array $node = null, array $pat
3838
*/
3939
public function getLocations(): ?array
4040
{
41-
return [$this->node["loc"]] ?? null;
41+
// get location of error
42+
$location = $this->node["loc"] ?? null;
43+
44+
// return null if location is null
45+
if ($location === null)
46+
return null;
47+
48+
// return location
49+
return [$location];
4250
}
4351

4452
/**
@@ -60,7 +68,7 @@ public function getSimplifiedPath(): ?array
6068
{
6169
$simplifiedPath = [];
6270
$currentPathField = $this->path;
63-
while($currentPathField !== null){
71+
while ($currentPathField !== null) {
6472
$simplifiedPath[] = $currentPathField[0];
6573
$currentPathField = $currentPathField[2];
6674
}

0 commit comments

Comments
 (0)