Improvements in config validation

This commit is contained in:
Vladimir Razuvaev 2017-06-12 22:48:48 +07:00
parent e7cde5ecf3
commit ffc4542cd0
2 changed files with 8 additions and 4 deletions

View File

@ -187,12 +187,14 @@ class Config
$arrValue = ['name' => $arrValue];
}
if (!$arrValue instanceof FieldDefinition) {
Utils::invariant(is_array($arrValue), $err, $arrKey, Utils::getVariableType($arrValue));
if ($def->flags & self::KEY_AS_NAME && is_string($arrKey)) {
$arrValue += ['name' => $arrKey];
}
self::validateMap($typeName, $arrValue, $def->definition, "$pathStr:$arrKey");
}
} else {
self::validateEntry($typeName, $arrKey, $arrValue, $def->definition, "$pathStr:$arrKey");
}

View File

@ -29,6 +29,8 @@ class InputObjectType extends Type implements InputType
$config['name'] = $this->tryInferName();
}
Utils::invariant(!empty($config['name']), 'Every type is expected to have name');
Config::validate($config, [
'name' => Config::NAME | Config::REQUIRED,
'fields' => Config::arrayOf([