diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 7ef5fa0..a52f239 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -918,7 +918,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..a459c9e 100644 --- a/tests/Executor/ResolveTest.php +++ b/tests/Executor/ResolveTest.php @@ -60,6 +60,30 @@ 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 class($_secret) { + public function __construct($_secret) { + $this->_secret = $_secret; + } + public function __invoke() { + return $this->_secret; + } + } + ]; + $this->assertEquals( + ['data' => ['test' => $_secret]], + GraphQL::execute($schema, '{ test }', $source) + ); + } + /** * @it default function passes args and context */ @@ -114,4 +138,4 @@ class ResolveTest extends \PHPUnit_Framework_TestCase GraphQL::execute($schema, '{ test(aInt: -123, aStr: "String!") }', 'Source!') ); } -} \ No newline at end of file +}