From 3ba187ec04fa82af5f14d0fb6b05f7cbbe32da96 Mon Sep 17 00:00:00 2001 From: vladar Date: Fri, 21 Oct 2016 00:06:34 +0700 Subject: [PATCH] Added missing one-line shorthand for field arguments --- src/Type/Definition/FieldArgument.php | 3 +++ src/Type/Definition/FieldDefinition.php | 2 +- tests/Type/DefinitionTest.php | 14 +++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Type/Definition/FieldArgument.php b/src/Type/Definition/FieldArgument.php index 8103ab6..8385b06 100644 --- a/src/Type/Definition/FieldArgument.php +++ b/src/Type/Definition/FieldArgument.php @@ -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; diff --git a/src/Type/Definition/FieldDefinition.php b/src/Type/Definition/FieldDefinition.php index a6c59b9..4febcfd 100644 --- a/src/Type/Definition/FieldDefinition.php +++ b/src/Type/Definition/FieldDefinition.php @@ -16,7 +16,7 @@ class FieldDefinition public $name; /** - * @var array + * @var FieldArgument[] */ public $args; diff --git a/tests/Type/DefinitionTest.php b/tests/Type/DefinitionTest.php index 0a1c3b3..d2a0b68 100644 --- a/tests/Type/DefinitionTest.php +++ b/tests/Type/DefinitionTest.php @@ -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);