mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-26 14:56:03 +03:00
26 lines
509 B
PHP
26 lines
509 B
PHP
<?php
|
|
namespace GraphQL;
|
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
class FormattedError
|
|
{
|
|
/**
|
|
* @param $error
|
|
* @param SourceLocation[] $locations
|
|
* @return array
|
|
*/
|
|
public static function create($error, array $locations = [])
|
|
{
|
|
$formatted = [
|
|
'message' => $error
|
|
];
|
|
|
|
if (!empty($locations)) {
|
|
$formatted['locations'] = array_map(function($loc) { return $loc->toArray();}, $locations);
|
|
}
|
|
|
|
return $formatted;
|
|
}
|
|
}
|