mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 21:06:05 +03:00
cf276340a4
If a GraphQLError represents multiple nodes across files (could happen for validation across multiple parsed files) then the reported locations and printError output can be incorrect for the second node. This ensures locations are derived from nodes whenever possible to get correct location and amends comment documentation. ref: graphql/graphql-js#1131
62 lines
1.2 KiB
PHP
62 lines
1.2 KiB
PHP
<?php
|
|
namespace GraphQL\Tests\Error;
|
|
|
|
use GraphQL\Error\Error;
|
|
use GraphQL\Error\FormattedError;
|
|
use GraphQL\Language\Parser;
|
|
use GraphQL\Language\Source;
|
|
|
|
class PrintErrorTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
// Describe printError
|
|
|
|
/**
|
|
* @it prints an error with nodes from different sources
|
|
*/
|
|
public function testPrintsAnErrorWithNodesFromDifferentSources()
|
|
{
|
|
$sourceA = Parser::parse(new Source('type Foo {
|
|
field: String
|
|
}',
|
|
'SourceA'
|
|
));
|
|
|
|
$fieldTypeA = $sourceA->definitions[0]->fields[0]->type;
|
|
|
|
$sourceB = Parser::parse(new Source('type Foo {
|
|
field: Int
|
|
}',
|
|
'SourceB'
|
|
));
|
|
|
|
$fieldTypeB = $sourceB->definitions[0]->fields[0]->type;
|
|
|
|
|
|
$error = new Error(
|
|
'Example error with two nodes',
|
|
[
|
|
$fieldTypeA,
|
|
$fieldTypeB,
|
|
]
|
|
);
|
|
|
|
$this->assertEquals(
|
|
'Example error with two nodes
|
|
|
|
SourceA (2:10)
|
|
1: type Foo {
|
|
2: field: String
|
|
^
|
|
3: }
|
|
|
|
SourceB (2:10)
|
|
1: type Foo {
|
|
2: field: Int
|
|
^
|
|
3: }
|
|
',
|
|
FormattedError::printError($error)
|
|
);
|
|
}
|
|
}
|