mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
Fixes for definition config validation after recent changes
This commit is contained in:
parent
083cb4e3f2
commit
f548de59fe
@ -21,6 +21,7 @@ class Config
|
||||
|
||||
const REQUIRED = 65536;
|
||||
const KEY_AS_NAME = 131072;
|
||||
const MAYBE_THUNK = 262144;
|
||||
|
||||
private static $enableValidation = false;
|
||||
|
||||
@ -105,7 +106,11 @@ class Config
|
||||
if ($def->flags & self::REQUIRED === 0 && $value === null) {
|
||||
return ;
|
||||
}
|
||||
Utils::invariant(is_array($value), $err, 'array');
|
||||
if (($def->flags & self::MAYBE_THUNK) > 0) {
|
||||
Utils::invariant(is_array($value) || is_callable($value), $err, 'array or callable');
|
||||
} else {
|
||||
Utils::invariant(is_array($value), $err, 'array');
|
||||
}
|
||||
|
||||
if (!empty($def->isMap)) {
|
||||
if ($def->flags & self::KEY_AS_NAME) {
|
||||
|
@ -21,7 +21,7 @@ class InputObjectType extends Type implements InputType
|
||||
'type' => Config::INPUT_TYPE | Config::REQUIRED,
|
||||
'defaultValue' => Config::ANY,
|
||||
'description' => Config::STRING
|
||||
], Config::KEY_AS_NAME),
|
||||
], Config::KEY_AS_NAME | Config::MAYBE_THUNK),
|
||||
'description' => Config::STRING
|
||||
]);
|
||||
|
||||
|
@ -55,7 +55,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
||||
'name' => Config::STRING,
|
||||
'fields' => Config::arrayOf(
|
||||
FieldDefinition::getDefinition(),
|
||||
Config::KEY_AS_NAME
|
||||
Config::KEY_AS_NAME | Config::MAYBE_THUNK
|
||||
),
|
||||
'resolveType' => Config::CALLBACK, // function($value, ResolveInfo $info) => ObjectType
|
||||
'description' => Config::STRING
|
||||
|
@ -79,11 +79,12 @@ class ObjectType extends Type implements OutputType, CompositeType
|
||||
'name' => Config::STRING | Config::REQUIRED,
|
||||
'fields' => Config::arrayOf(
|
||||
FieldDefinition::getDefinition(),
|
||||
Config::KEY_AS_NAME
|
||||
Config::KEY_AS_NAME | Config::MAYBE_THUNK
|
||||
),
|
||||
'description' => Config::STRING,
|
||||
'interfaces' => Config::arrayOf(
|
||||
Config::INTERFACE_TYPE
|
||||
Config::INTERFACE_TYPE,
|
||||
Config::MAYBE_THUNK
|
||||
),
|
||||
'isTypeOf' => Config::CALLBACK, // ($value, ResolveInfo $info) => boolean
|
||||
'resolveField' => Config::CALLBACK
|
||||
|
Loading…
Reference in New Issue
Block a user