mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
Several minor tweaks
This commit is contained in:
parent
9941a0143a
commit
2ef58a615f
@ -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_string($name)) {
|
||||
$field = ['name' => $name, 'type' => $field];
|
||||
} else {
|
||||
throw new InvariantViolation(
|
||||
"Unexpected field definition for type $typeName at key $name: " . Utils::printSafe($field)
|
||||
);
|
||||
}
|
||||
} elseif (!isset($field['name']) && is_string($name)) {
|
||||
if (is_array($field)) {
|
||||
if (!isset($field['name']) && is_string($name)) {
|
||||
$field['name'] = $name;
|
||||
}
|
||||
$map[$name] = self::create($field, $typeName);
|
||||
$fieldDef = self::create($field, $parentTypeName);
|
||||
} else if ($field instanceof FieldDefinition) {
|
||||
$fieldDef = $field;
|
||||
} else {
|
||||
if (is_string($name)) {
|
||||
$fieldDef = self::create(['name' => $name, 'type' => $field], $parentTypeName);
|
||||
} else {
|
||||
throw new InvariantViolation(
|
||||
"Unexpected field definition for type $parentTypeName at key $name: " . Utils::printSafe($field)
|
||||
);
|
||||
}
|
||||
}
|
||||
$map[$fieldDef->name] = $fieldDef;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
@ -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.');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user