mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-11 10:09:24 +03:00
Default resolve callables
This commit is contained in:
parent
848f9c3edf
commit
e07c86bd5e
@ -918,7 +918,7 @@ class Executor
|
||||
}
|
||||
}
|
||||
|
||||
return $property instanceof \Closure ? $property($source, $args, $context) : $property;
|
||||
return is_callable($property) ? $property($source, $args, $context) : $property;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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!')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user