This commit is contained in:
vladar 2017-01-19 11:55:10 +07:00
commit 8e75cc3d60
4 changed files with 20 additions and 6 deletions

View File

@ -1,7 +1,9 @@
<?php
// Test this using following command
// php -S localhost:8080 ./graphql.php
require_once '../../vendor/autoload.php';
// php -S localhost:8080 ./graphql.php &
// curl http://localhost:8080 -d "query { echo(message: \"Hello\") }"
// curl http://localhost:8080 -d "mutation { sum(x: 2, y: 2) }"
require_once __DIR__ . '/../../vendor/autoload.php';
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;

View File

@ -1,7 +1,7 @@
<?php
// Test this using following command
// php -S localhost:8080 ./index.php
require_once '../../vendor/autoload.php';
// php -S localhost:8080 ./graphql.php
require_once __DIR__ . '/../../vendor/autoload.php';
use \GraphQL\Examples\Blog\Types;
use \GraphQL\Examples\Blog\AppContext;

View File

@ -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);

View File

@ -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) {