diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 187a4aa..ae23464 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -913,7 +913,7 @@ class Executor } } - return $property instanceof \Closure ? $property($source, $args, $context) : $property; + return is_callable($property) ? $property($source, $args, $context) : $property; } /** diff --git a/tests/Executor/ResolveTest.php b/tests/Executor/ResolveTest.php index f3f6cf4..49e23b6 100644 --- a/tests/Executor/ResolveTest.php +++ b/tests/Executor/ResolveTest.php @@ -60,6 +60,23 @@ class ResolveTest extends \PHPUnit_Framework_TestCase ); } + /** + * @it default function calls callables + */ + public function testDefaultFunctionCallsCallables() + { + $schema = $this->buildSchema(['type' => Type::string()]); + $_secret = 'secretValue' . uniqid(); + + $source = [ + 'test' => new ResolveTestCallableFixture($_secret) + ]; + $this->assertEquals( + ['data' => ['test' => $_secret]], + GraphQL::execute($schema, '{ test }', $source) + ); + } + /** * @it default function passes args and context */ @@ -114,4 +131,19 @@ class ResolveTest extends \PHPUnit_Framework_TestCase GraphQL::execute($schema, '{ test(aInt: -123, aStr: "String!") }', 'Source!') ); } -} \ No newline at end of file +} + +class ResolveTestCallableFixture +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + public function __invoke($root, $args, $context) + { + return $this->value; + } +}