mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 12:56: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' => [
|
[
|
||||||
'kind' => 'SCALAR',
|
'name' => 'a',
|
||||||
'name' => 'String',
|
'type' => [
|
||||||
'ofType' => null],
|
'kind' => 'SCALAR',
|
||||||
|
'name' => 'String',
|
||||||
|
'ofType' => null
|
||||||
|
],
|
||||||
'defaultValue' => '"foo"'
|
'defaultValue' => '"foo"'
|
||||||
],
|
],
|
||||||
['name' => 'b', 'type' => [
|
[
|
||||||
'kind' => 'LIST',
|
'name' => 'b',
|
||||||
'name' => null,
|
'type' => [
|
||||||
'ofType' => ['kind' => 'SCALAR', 'name' => 'String', 'ofType' => null]],
|
'kind' => 'LIST',
|
||||||
|
'name' => 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