Fixes for definition config validation after recent changes

This commit is contained in:
vladar 2016-02-25 15:23:42 +06:00
parent 083cb4e3f2
commit f548de59fe
4 changed files with 11 additions and 5 deletions

View File

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

View File

@ -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
]);

View File

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

View File

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