diff --git a/src/Type/Definition/Type.php b/src/Type/Definition/Type.php index b483d7f..f4a1467 100644 --- a/src/Type/Definition/Type.php +++ b/src/Type/Definition/Type.php @@ -1,6 +1,7 @@ [ - 'type' => Type::listOf(Type::nonNull([__CLASS__, '_type'])), + 'type' => Type::listOf(Type::nonNull(self::_type())), 'resolve' => function ($type, $args, $context, ResolveInfo $info) { if ($type instanceof InterfaceType || $type instanceof UnionType) { return $info->schema->getPossibleTypes($type); diff --git a/tests/Executor/ExecutorSchemaTest.php b/tests/Executor/ExecutorSchemaTest.php index ff57ebb..4da1af6 100644 --- a/tests/Executor/ExecutorSchemaTest.php +++ b/tests/Executor/ExecutorSchemaTest.php @@ -29,20 +29,20 @@ class ExecutorSchemaTest extends \PHPUnit_Framework_TestCase $BlogAuthor = new ObjectType([ 'name' => 'Author', - 'fields' => [ - 'id' => ['type' => Type::string()], - 'name' => ['type' => Type::string()], - 'pic' => [ - 'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]], - 'type' => $BlogImage, - 'resolve' => function ($obj, $args) { - return $obj['pic']($args['width'], $args['height']); - } - ], - 'recentArticle' => ['type' => function () use (&$BlogArticle) { - return $BlogArticle; - }] - ] + 'fields' => function() use (&$BlogArticle, &$BlogImage) { + return [ + 'id' => ['type' => Type::string()], + 'name' => ['type' => Type::string()], + 'pic' => [ + 'args' => ['width' => ['type' => Type::int()], 'height' => ['type' => Type::int()]], + 'type' => $BlogImage, + 'resolve' => function ($obj, $args) { + return $obj['pic']($args['width'], $args['height']); + } + ], + 'recentArticle' => $BlogArticle + ]; + } ]); $BlogArticle = new ObjectType([ diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index 6bd7c77..07daaa3 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -116,23 +116,25 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase $deepDataType = null; $dataType = new ObjectType([ 'name' => 'DataType', - 'fields' => [ - 'a' => [ 'type' => Type::string() ], - 'b' => [ 'type' => Type::string() ], - 'c' => [ 'type' => Type::string() ], - 'd' => [ 'type' => Type::string() ], - 'e' => [ 'type' => Type::string() ], - 'f' => [ 'type' => Type::string() ], - 'pic' => [ - 'args' => [ 'size' => ['type' => Type::int() ] ], - 'type' => Type::string(), - 'resolve' => function($obj, $args) { - return $obj['pic']($args['size']); - } - ], - 'promise' => ['type' => function() use (&$dataType) {return $dataType;}], - 'deep' => [ 'type' => function() use(&$deepDataType) {return $deepDataType; }], - ] + 'fields' => function() use (&$dataType, &$deepDataType) { + return [ + 'a' => [ 'type' => Type::string() ], + 'b' => [ 'type' => Type::string() ], + 'c' => [ 'type' => Type::string() ], + 'd' => [ 'type' => Type::string() ], + 'e' => [ 'type' => Type::string() ], + 'f' => [ 'type' => Type::string() ], + 'pic' => [ + 'args' => [ 'size' => ['type' => Type::int() ] ], + 'type' => Type::string(), + 'resolve' => function($obj, $args) { + return $obj['pic']($args['size']); + } + ], + 'promise' => ['type' => $dataType], + 'deep' => ['type' => $deepDataType], + ]; + } ]); $deepDataType = new ObjectType([ @@ -170,25 +172,25 @@ class ExecutorTest extends \PHPUnit_Framework_TestCase $Type = new ObjectType([ 'name' => 'Type', - 'fields' => [ - 'a' => ['type' => Type::string(), 'resolve' => function () { - return 'Apple'; - }], - 'b' => ['type' => Type::string(), 'resolve' => function () { - return 'Banana'; - }], - 'c' => ['type' => Type::string(), 'resolve' => function () { - return 'Cherry'; - }], - 'deep' => [ - 'type' => function () use (&$Type) { - return $Type; - }, - 'resolve' => function () { - return []; - } - ] - ] + 'fields' => function() use (&$Type) { + return [ + 'a' => ['type' => Type::string(), 'resolve' => function () { + return 'Apple'; + }], + 'b' => ['type' => Type::string(), 'resolve' => function () { + return 'Banana'; + }], + 'c' => ['type' => Type::string(), 'resolve' => function () { + return 'Cherry'; + }], + 'deep' => [ + 'type' => $Type, + 'resolve' => function () { + return []; + } + ] + ]; + } ]); $schema = new Schema(['query' => $Type]); $expected = [ diff --git a/tests/Executor/NonNullTest.php b/tests/Executor/NonNullTest.php index 6bf619d..6aa147f 100644 --- a/tests/Executor/NonNullTest.php +++ b/tests/Executor/NonNullTest.php @@ -58,16 +58,14 @@ class NonNullTest extends \PHPUnit_Framework_TestCase $dataType = new ObjectType([ 'name' => 'DataType', - 'fields' => [ - 'sync' => ['type' => Type::string()], - 'nonNullSync' => ['type' => Type::nonNull(Type::string())], - 'nest' => ['type' => function () use (&$dataType) { - return $dataType; - }], - 'nonNullNest' => ['type' => function () use (&$dataType) { - return Type::nonNull($dataType); - }] - ] + 'fields' => function() use (&$dataType) { + return [ + 'sync' => ['type' => Type::string()], + 'nonNullSync' => ['type' => Type::nonNull(Type::string())], + 'nest' => $dataType, + 'nonNullNest' => Type::nonNull($dataType) + ]; + } ]); $this->schema = new Schema(['query' => $dataType]); diff --git a/tests/Type/DefinitionTest.php b/tests/Type/DefinitionTest.php index 0292ac8..e6af327 100644 --- a/tests/Type/DefinitionTest.php +++ b/tests/Type/DefinitionTest.php @@ -92,15 +92,17 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase $this->blogAuthor = new ObjectType([ 'name' => 'Author', - 'fields' => [ - 'id' => ['type' => Type::string()], - 'name' => ['type' => Type::string()], - 'pic' => [ 'type' => $this->blogImage, 'args' => [ - 'width' => ['type' => Type::int()], - 'height' => ['type' => Type::int()] - ]], - 'recentArticle' => ['type' => function() {return $this->blogArticle;}], - ], + 'fields' => function() { + return [ + 'id' => ['type' => Type::string()], + 'name' => ['type' => Type::string()], + 'pic' => [ 'type' => $this->blogImage, 'args' => [ + 'width' => ['type' => Type::int()], + 'height' => ['type' => Type::int()] + ]], + 'recentArticle' => $this->blogArticle, + ]; + }, ]); $this->blogArticle = new ObjectType([ diff --git a/tests/Type/SchemaValidatorTest.php b/tests/Type/SchemaValidatorTest.php index b8c3e77..67bf0bf 100644 --- a/tests/Type/SchemaValidatorTest.php +++ b/tests/Type/SchemaValidatorTest.php @@ -398,9 +398,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase foreach ($kinds as $kind) { $someOutputType = new $kind([ 'name' => 'SomeOutputType', - 'fields' => [ - 'sneaky' => ['type' => function() {return $this->someInputObjectType;}] - ] + 'fields' => function() { + return [ + 'sneaky' => $this->someInputObjectType + ]; + } ]); $schema = new Schema(['query' => $someOutputType]); @@ -545,9 +547,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase { $someIncorrectInputType = new InputObjectType([ 'name' => 'SomeIncorrectInputType', - 'fields' => [ - 'val' => ['type' => function() use ($argType) {return $argType;} ] - ] + 'fields' => function() use ($argType) { + return [ + 'val' => ['type' => $argType ] + ]; + } ]); $queryType = new ObjectType([ diff --git a/tests/Validator/QuerySecuritySchema.php b/tests/Validator/QuerySecuritySchema.php index aa95b88..771af77 100644 --- a/tests/Validator/QuerySecuritySchema.php +++ b/tests/Validator/QuerySecuritySchema.php @@ -59,24 +59,24 @@ class QuerySecuritySchema self::$humanType = new ObjectType( [ 'name' => 'Human', - 'fields' => [ - 'firstName' => ['type' => Type::nonNull(Type::string())], - 'dogs' => [ - 'type' => function () { - return Type::nonNull( + 'fields' => function() { + return [ + 'firstName' => ['type' => Type::nonNull(Type::string())], + 'dogs' => [ + 'type' => Type::nonNull( Type::listOf( Type::nonNull(self::buildDogType()) ) - ); - }, - 'complexity' => function ($childrenComplexity, $args) { - $complexity = isset($args['name']) ? 1 : 10; + ), + 'complexity' => function ($childrenComplexity, $args) { + $complexity = isset($args['name']) ? 1 : 10; - return $childrenComplexity + $complexity; - }, - 'args' => ['name' => ['type' => Type::string()]], - ], - ], + return $childrenComplexity + $complexity; + }, + 'args' => ['name' => ['type' => Type::string()]], + ], + ]; + }, ] ); diff --git a/tests/Validator/TestCase.php b/tests/Validator/TestCase.php index f8d2efc..c58d51f 100644 --- a/tests/Validator/TestCase.php +++ b/tests/Validator/TestCase.php @@ -94,16 +94,18 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase $Cat = new ObjectType([ 'name' => 'Cat', 'isTypeOf' => function() {return true;}, - 'fields' => [ - 'name' => [ - 'type' => Type::string(), - 'args' => [ 'surname' => [ 'type' => Type::boolean() ] ] - ], - 'nickname' => ['type' => Type::string()], - 'meows' => ['type' => Type::boolean()], - 'meowVolume' => ['type' => Type::int()], - 'furColor' => ['type' => function() use (&$FurColor) {return $FurColor;}] - ], + 'fields' => function() use (&$FurColor) { + return [ + 'name' => [ + 'type' => Type::string(), + 'args' => [ 'surname' => [ 'type' => Type::boolean() ] ] + ], + 'nickname' => ['type' => Type::string()], + 'meows' => ['type' => Type::boolean()], + 'meowVolume' => ['type' => Type::int()], + 'furColor' => $FurColor + ]; + }, 'interfaces' => [$Being, $Pet] ]); @@ -128,15 +130,17 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase 'name' => 'Human', 'isTypeOf' => function() {return true;}, 'interfaces' => [$Being, $Intelligent], - 'fields' => [ - 'name' => [ - 'type' => Type::string(), - 'args' => ['surname' => ['type' => Type::boolean()]] - ], - 'pets' => ['type' => Type::listOf($Pet)], - 'relatives' => ['type' => function() use (&$Human) {return Type::listOf($Human); }], - 'iq' => ['type' => Type::int()] - ] + 'fields' => function() use (&$Human, $Pet) { + return [ + 'name' => [ + 'type' => Type::string(), + 'args' => ['surname' => ['type' => Type::boolean()]] + ], + 'pets' => ['type' => Type::listOf($Pet)], + 'relatives' => ['type' => Type::listOf($Human)], + 'iq' => ['type' => Type::int()] + ]; + } ]); $Alien = new ObjectType([