Added missing one-line shorthand for field arguments

This commit is contained in:
vladar 2016-10-21 00:06:34 +07:00
parent fc37515ec2
commit 3ba187ec04
3 changed files with 17 additions and 2 deletions

View File

@ -48,6 +48,9 @@ class FieldArgument
{
$map = [];
foreach ($config as $name => $argConfig) {
if (!is_array($argConfig)) {
$argConfig = ['type' => $argConfig];
}
$map[] = new self($argConfig + ['name' => $name]);
}
return $map;

View File

@ -16,7 +16,7 @@ class FieldDefinition
public $name;
/**
* @var array<GraphQLFieldArgument>
* @var FieldArgument[]
*/
public $args;

View File

@ -625,7 +625,13 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
'fields' => function() use (&$interface) {
return [
'value' => Type::string(),
'nested' => $interface
'nested' => $interface,
'withArg' => [
'type' => Type::string(),
'args' => [
'arg1' => Type::int()
]
]
];
}
]);
@ -647,6 +653,12 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(Type::string(), $valueField->getType());
$this->assertEquals($interface, $nestedField->getType());
$withArg = $schema->getType('SomeInterface')->getField('withArg');
$this->assertEquals(Type::string(), $withArg->getType());
$this->assertEquals('arg1', $withArg->args[0]->name);
$this->assertEquals(Type::int(), $withArg->args[0]->getType());
$testField = $schema->getType('Query')->getField('test');
$this->assertEquals($interface, $testField->getType());
$this->assertEquals('test', $testField->name);