Several minor tweaks

This commit is contained in:
vladar 2016-10-23 05:06:36 +07:00
parent 9941a0143a
commit 2ef58a615f
2 changed files with 14 additions and 9 deletions

View File

@ -91,25 +91,30 @@ class FieldDefinition
/**
* @param array|Config $fields
* @param string $typeName
* @param string $parentTypeName
* @return array
*/
public static function createMap(array $fields, $typeName = null)
public static function createMap(array $fields, $parentTypeName = null)
{
$map = [];
foreach ($fields as $name => $field) {
if (!is_array($field)) {
if (is_array($field)) {
if (!isset($field['name']) && is_string($name)) {
$field['name'] = $name;
}
$fieldDef = self::create($field, $parentTypeName);
} else if ($field instanceof FieldDefinition) {
$fieldDef = $field;
} else {
if (is_string($name)) {
$field = ['name' => $name, 'type' => $field];
$fieldDef = self::create(['name' => $name, 'type' => $field], $parentTypeName);
} else {
throw new InvariantViolation(
"Unexpected field definition for type $typeName at key $name: " . Utils::printSafe($field)
"Unexpected field definition for type $parentTypeName at key $name: " . Utils::printSafe($field)
);
}
} elseif (!isset($field['name']) && is_string($name)) {
$field['name'] = $name;
}
$map[$name] = self::create($field, $typeName);
$map[$fieldDef->name] = $fieldDef;
}
return $map;
}

View File

@ -26,7 +26,7 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
/**
* ScalarType constructor.
*/
protected function __construct()
public function __construct()
{
Utils::invariant($this->name, 'Type must be named.');
}