From d022b19b4ea256573ca92fc33cb48a91d9d3c1e3 Mon Sep 17 00:00:00 2001
From: OwlyCode <tmaindron@gmail.com>
Date: Thu, 12 Jan 2017 16:48:24 +0100
Subject: [PATCH] Added compatibility with php7 error handling.

---
 src/Error/Error.php       | 7 +++++--
 src/Executor/Executor.php | 9 +++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/Error/Error.php b/src/Error/Error.php
index 56241d9..c613f86 100644
--- a/src/Error/Error.php
+++ b/src/Error/Error.php
@@ -89,6 +89,9 @@ class Error extends \Exception implements \JsonSerializable
         } else if ($error instanceof \Exception) {
             $message = $error->getMessage();
             $originalError = $error;
+        } else if ($error instanceof \Error) {
+            $message = $error->getMessage();
+            $originalError = $error;
         } else {
             $message = (string) $error;
         }
@@ -119,9 +122,9 @@ class Error extends \Exception implements \JsonSerializable
      * @param Source $source
      * @param array|null $positions
      * @param array|null $path
-     * @param \Exception $previous
+     * @param \Exception|\Error $previous
      */
-    public function __construct($message, $nodes = null, Source $source = null, $positions = null, $path = null, \Exception $previous = null)
+    public function __construct($message, $nodes = null, Source $source = null, $positions = null, $path = null, $previous = null)
     {
         parent::__construct($message, 0, $previous);
 
diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php
index 602b693..c6a2fda 100644
--- a/src/Executor/Executor.php
+++ b/src/Executor/Executor.php
@@ -680,6 +680,8 @@ class Executor
             return $resolveFn($source, $args, $context, $info);
         } catch (\Exception $error) {
             return $error;
+        } catch (\Error $error) {
+            return $error;
         }
     }
 
@@ -778,6 +780,8 @@ class Executor
             return $completed;
         } catch (\Exception $error) {
             throw Error::createLocatedError($error, $fieldNodes, $path);
+        } catch (\Error $error) {
+            throw Error::createLocatedError($error, $fieldNodes, $path);
         }
     }
 
@@ -810,6 +814,7 @@ class Executor
      * @return array|null|Promise
      * @throws Error
      * @throws \Exception
+     * @throws \Error
      */
     private function completeValue(
         Type $returnType,
@@ -835,6 +840,10 @@ class Executor
             throw $result;
         }
 
+        if ($result instanceof \Error) {
+            throw $result;
+        }
+
         // If field type is NonNull, complete for inner type, and throw field error
         // if result is null.
         if ($returnType instanceof NonNull) {