From 1acddf4e22e59c1d946075cb912e05eccd49e111 Mon Sep 17 00:00:00 2001 From: spawnia Date: Thu, 28 Mar 2019 11:25:57 +0100 Subject: [PATCH 1/3] Mention default value definition for enum args in docs --- docs/type-system/input-types.md | 2 +- docs/type-system/object-types.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/type-system/input-types.md b/docs/type-system/input-types.md index f48b83f..1b7ffc8 100644 --- a/docs/type-system/input-types.md +++ b/docs/type-system/input-types.md @@ -114,7 +114,7 @@ Option | Type | Notes name | `string` | **Required.** Name of the input field. When not set - inferred from **fields** array key type | `Type` | **Required.** Instance of one of [Input Types](input-types.md) (**Scalar**, **Enum**, **InputObjectType** + any combination of those with **nonNull** and **listOf** modifiers) description | `string` | Plain-text description of this input field for clients (e.g. used by [GraphiQL](https://github.com/graphql/graphiql) for auto-generated documentation) -defaultValue | `scalar` | Default value of this input field +defaultValue | `scalar` | Default value of this input field. Use the internal value if specifying a default for an **enum** type # Using Input Object Type In the example above we defined our InputObjectType. Now let's use it in one of field arguments: diff --git a/docs/type-system/object-types.md b/docs/type-system/object-types.md index a853be3..9c1f2fb 100644 --- a/docs/type-system/object-types.md +++ b/docs/type-system/object-types.md @@ -94,7 +94,7 @@ Option | Type | Notes name | `string` | **Required.** Name of the argument. When not set - inferred from **args** array key type | `Type` | **Required.** Instance of one of [Input Types](input-types.md) (**scalar**, **enum**, **InputObjectType** + any combination of those with **nonNull** and **listOf** modifiers) description | `string` | Plain-text description of this argument for clients (e.g. used by [GraphiQL](https://github.com/graphql/graphiql) for auto-generated documentation) -defaultValue | `scalar` | Default value for this argument +defaultValue | `scalar` | Default value for this argument. Use the internal value if specifying a default for an **enum** type # Shorthand field definitions Fields can be also defined in **shorthand** notation (with only **name** and **type** options): From ddebd9a414d58c5ed105328309bab3a1cb09743c Mon Sep 17 00:00:00 2001 From: spawnia Date: Thu, 28 Mar 2019 11:26:30 +0100 Subject: [PATCH 2/3] Add test for default enum input coercion --- tests/Executor/ExecutorTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index fe6768c..d3679e8 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -11,6 +11,7 @@ use GraphQL\Executor\Executor; use GraphQL\Language\Parser; use GraphQL\Tests\Executor\TestClasses\NotSpecial; use GraphQL\Tests\Executor\TestClasses\Special; +use GraphQL\Type\Definition\EnumType; use GraphQL\Type\Definition\InputObjectType; use GraphQL\Type\Definition\InterfaceType; use GraphQL\Type\Definition\ObjectType; @@ -1108,6 +1109,16 @@ class ExecutorTest extends TestCase ], ]), 'defaultValue' => ['a' => 1, 'b' => 'test'], ], + 'i' => [ + 'type' => new EnumType([ + 'name' => 'EnumType', + 'values' => [ + 'VALUE1' => 1, + 'VALUE2' => 2, + ] + ]), + 'defaultValue' => 1 + ] ], ], ], @@ -1117,7 +1128,7 @@ class ExecutorTest extends TestCase $query = Parser::parse('{ field }'); $result = Executor::execute($schema, $query); $expected = [ - 'data' => ['field' => '{"a":1,"b":null,"c":0,"d":false,"e":"0","f":"some-string","h":{"a":1,"b":"test"}}'], + 'data' => ['field' => '{"a":1,"b":null,"c":0,"d":false,"e":"0","f":"some-string","h":{"a":1,"b":"test"},"i":1}'], ]; self::assertEquals($expected, $result->toArray()); From db915d881212e8eb8c24934e8e1db728214c96a2 Mon Sep 17 00:00:00 2001 From: spawnia Date: Fri, 29 Mar 2019 09:27:33 +0100 Subject: [PATCH 3/3] Fix codestyle --- tests/Executor/ExecutorTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index d3679e8..9f5480f 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -1101,13 +1101,14 @@ class ExecutorTest extends TestCase 'f' => ['type' => Type::int(), 'defaultValue' => 'some-string'], 'g' => ['type' => Type::boolean()], 'h' => [ - 'type' => new InputObjectType([ + 'type' => new InputObjectType([ 'name' => 'ComplexType', 'fields' => [ 'a' => ['type' => Type::int()], 'b' => ['type' => Type::string()], ], - ]), 'defaultValue' => ['a' => 1, 'b' => 'test'], + ]), + 'defaultValue' => ['a' => 1, 'b' => 'test'], ], 'i' => [ 'type' => new EnumType([ @@ -1115,10 +1116,10 @@ class ExecutorTest extends TestCase 'values' => [ 'VALUE1' => 1, 'VALUE2' => 2, - ] + ], ]), - 'defaultValue' => 1 - ] + 'defaultValue' => 1, + ], ], ], ],