GraphQL\Error\FormattedError::create PHP Method

create() public static method

Deprecation: as of 8.0
public static create ( $error, array $locations = [] ) : array
$error
$locations array
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;
    }

Usage Example

Example #1
0
 /**
  * @it evaluates mutations correctly in the presense of a failed mutation
  */
 public function testEvaluatesMutationsCorrectlyInThePresenseOfAFailedMutation()
 {
     $doc = 'mutation M {
   first: immediatelyChangeTheNumber(newNumber: 1) {
     theNumber
   },
   second: promiseToChangeTheNumber(newNumber: 2) {
     theNumber
   },
   third: failToChangeTheNumber(newNumber: 3) {
     theNumber
   }
   fourth: promiseToChangeTheNumber(newNumber: 4) {
     theNumber
   },
   fifth: immediatelyChangeTheNumber(newNumber: 5) {
     theNumber
   }
   sixth: promiseAndFailToChangeTheNumber(newNumber: 6) {
     theNumber
   }
 }';
     $ast = Parser::parse($doc);
     $mutationResult = Executor::execute($this->schema(), $ast, new Root(6));
     $expected = ['data' => ['first' => ['theNumber' => 1], 'second' => ['theNumber' => 2], 'third' => null, 'fourth' => ['theNumber' => 4], 'fifth' => ['theNumber' => 5], 'sixth' => null], 'errors' => [FormattedError::create('Cannot change the number', [new SourceLocation(8, 7)]), FormattedError::create('Cannot change the number', [new SourceLocation(17, 7)])]];
     $this->assertArraySubset($expected, self::awaitPromise($mutationResult));
 }
All Usage Examples Of GraphQL\Error\FormattedError::create