mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 21:06:05 +03:00
Differentiate between input values with no default and with default = null
This commit is contained in:
parent
5a17ae8246
commit
04550f805f
@ -6,7 +6,9 @@ use GraphQL\Language\Printer;
|
|||||||
use GraphQL\Schema;
|
use GraphQL\Schema;
|
||||||
use GraphQL\Type\Definition\Directive;
|
use GraphQL\Type\Definition\Directive;
|
||||||
use GraphQL\Type\Definition\EnumType;
|
use GraphQL\Type\Definition\EnumType;
|
||||||
|
use GraphQL\Type\Definition\FieldArgument;
|
||||||
use GraphQL\Type\Definition\FieldDefinition;
|
use GraphQL\Type\Definition\FieldDefinition;
|
||||||
|
use GraphQL\Type\Definition\InputObjectField;
|
||||||
use GraphQL\Type\Definition\InputObjectType;
|
use GraphQL\Type\Definition\InputObjectType;
|
||||||
use GraphQL\Type\Definition\InterfaceType;
|
use GraphQL\Type\Definition\InterfaceType;
|
||||||
use GraphQL\Type\Definition\ListOfType;
|
use GraphQL\Type\Definition\ListOfType;
|
||||||
@ -613,8 +615,11 @@ EOD;
|
|||||||
],
|
],
|
||||||
'defaultValue' => [
|
'defaultValue' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
|
'description' =>
|
||||||
|
'A GraphQL-formatted string representing the default value for this input value.',
|
||||||
'resolve' => function ($inputValue) {
|
'resolve' => function ($inputValue) {
|
||||||
return $inputValue->defaultValue === null
|
/** @var FieldArgument|InputObjectField $inputValue */
|
||||||
|
return !$inputValue->defaultValueExists()
|
||||||
? null
|
? null
|
||||||
: Printer::doPrint(AST::astFromValue($inputValue->defaultValue, $inputValue->getType()));
|
: Printer::doPrint(AST::astFromValue($inputValue->defaultValue, $inputValue->getType()));
|
||||||
}
|
}
|
||||||
|
@ -1079,7 +1079,8 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'name' => 'TestInputObject',
|
'name' => 'TestInputObject',
|
||||||
'fields' => [
|
'fields' => [
|
||||||
'a' => ['type' => Type::string(), 'defaultValue' => 'foo'],
|
'a' => ['type' => Type::string(), 'defaultValue' => 'foo'],
|
||||||
'b' => ['type' => Type::listOf(Type::string())]
|
'b' => ['type' => Type::listOf(Type::string())],
|
||||||
|
'c' => ['type' => Type::string(), 'defaultValue' => null ]
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -1135,17 +1136,32 @@ class IntrospectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'kind' => 'INPUT_OBJECT',
|
'kind' => 'INPUT_OBJECT',
|
||||||
'name' => 'TestInputObject',
|
'name' => 'TestInputObject',
|
||||||
'inputFields' => [
|
'inputFields' => [
|
||||||
['name' => 'a', 'type' => [
|
[
|
||||||
|
'name' => 'a',
|
||||||
|
'type' => [
|
||||||
'kind' => 'SCALAR',
|
'kind' => 'SCALAR',
|
||||||
'name' => 'String',
|
'name' => 'String',
|
||||||
'ofType' => null],
|
'ofType' => null
|
||||||
|
],
|
||||||
'defaultValue' => '"foo"'
|
'defaultValue' => '"foo"'
|
||||||
],
|
],
|
||||||
['name' => 'b', 'type' => [
|
[
|
||||||
|
'name' => 'b',
|
||||||
|
'type' => [
|
||||||
'kind' => 'LIST',
|
'kind' => 'LIST',
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'ofType' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null]],
|
'ofType' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null]
|
||||||
|
],
|
||||||
'defaultValue' => null
|
'defaultValue' => null
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'c',
|
||||||
|
'type' => [
|
||||||
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'String',
|
||||||
|
'ofType' => null
|
||||||
|
],
|
||||||
|
'defaultValue' => 'null' // defaultValue was set (even if it was set to null)
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user