2015-07-15 23:05:46 +06:00
|
|
|
<?php
|
|
|
|
namespace GraphQL;
|
|
|
|
|
2015-08-17 02:53:11 +06:00
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
|
2015-07-15 23:05:46 +06:00
|
|
|
class FormattedError
|
|
|
|
{
|
2015-08-16 16:39:30 +06:00
|
|
|
/**
|
2015-08-17 02:53:11 +06:00
|
|
|
* @param $error
|
|
|
|
* @param SourceLocation[] $locations
|
2015-08-16 16:39:30 +06:00
|
|
|
* @return array
|
|
|
|
*/
|
2015-08-17 02:53:11 +06:00
|
|
|
public static function create($error, array $locations = [])
|
2015-08-16 16:39:30 +06:00
|
|
|
{
|
2015-08-17 02:53:11 +06:00
|
|
|
$formatted = [
|
|
|
|
'message' => $error
|
2015-08-16 16:39:30 +06:00
|
|
|
];
|
2015-08-17 02:53:11 +06:00
|
|
|
|
|
|
|
if (!empty($locations)) {
|
|
|
|
$formatted['locations'] = array_map(function($loc) { return $loc->toArray();}, $locations);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $formatted;
|
2015-07-15 23:05:46 +06:00
|
|
|
}
|
|
|
|
}
|