From 11c85ec757c2d9c9b88b84f893575a5270ea6927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20Tu=CC=88rich?= Date: Thu, 15 Sep 2022 10:49:16 +0200 Subject: [PATCH] update error location handling --- src/Errors/GraphQLError.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Errors/GraphQLError.php b/src/Errors/GraphQLError.php index 4a2ee26..5180c77 100644 --- a/src/Errors/GraphQLError.php +++ b/src/Errors/GraphQLError.php @@ -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; @@ -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]; } /** @@ -60,7 +68,7 @@ public function getSimplifiedPath(): ?array { $simplifiedPath = []; $currentPathField = $this->path; - while($currentPathField !== null){ + while ($currentPathField !== null) { $simplifiedPath[] = $currentPathField[0]; $currentPathField = $currentPathField[2]; }