mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +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 array|Config $fields
|
||||||
* @param string $typeName
|
* @param string $parentTypeName
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function createMap(array $fields, $typeName = null)
|
public static function createMap(array $fields, $parentTypeName = null)
|
||||||
{
|
{
|
||||||
$map = [];
|
$map = [];
|
||||||
foreach ($fields as $name => $field) {
|
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)) {
|
if (is_string($name)) {
|
||||||
$field = ['name' => $name, 'type' => $field];
|
$fieldDef = self::create(['name' => $name, 'type' => $field], $parentTypeName);
|
||||||
} else {
|
} else {
|
||||||
throw new InvariantViolation(
|
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;
|
return $map;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
|
|||||||
/**
|
/**
|
||||||
* ScalarType constructor.
|
* ScalarType constructor.
|
||||||
*/
|
*/
|
||||||
protected function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
Utils::invariant($this->name, 'Type must be named.');
|
Utils::invariant($this->name, 'Type must be named.');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user