graphql-php/src/FormattedError.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;
}
}