Merge pull request #465 from mll-lab/enum-default-values

Enum default values
This commit is contained in:
Vladimir Razuvaev 2019-03-29 15:41:12 +07:00 committed by GitHub
commit 11d32d4568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -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:

View File

@ -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):

View File

@ -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;
@ -1100,13 +1101,24 @@ 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([
'name' => 'EnumType',
'values' => [
'VALUE1' => 1,
'VALUE2' => 2,
],
]),
'defaultValue' => 1,
],
],
],
@ -1117,7 +1129,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());