|
3 | 3 |
|
4 | 4 | require_once __DIR__ . '/TestClasses.php'; |
5 | 5 |
|
6 | | -use GraphQL\Error\Error; |
| 6 | +use GraphQL\Error\InvariantViolation; |
7 | 7 | use GraphQL\Executor\Executor; |
8 | | -use GraphQL\Error\FormattedError; |
9 | 8 | use GraphQL\Language\Parser; |
10 | | -use GraphQL\Language\SourceLocation; |
11 | | -use GraphQL\Schema; |
| 9 | +use GraphQL\Type\Schema; |
12 | 10 | use GraphQL\Type\Definition\InputObjectType; |
13 | 11 | use GraphQL\Type\Definition\ObjectType; |
14 | 12 | use GraphQL\Type\Definition\Type; |
@@ -467,6 +465,47 @@ public function testReportsErrorForMissingNonNullableInputs() |
467 | 465 | $this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray()); |
468 | 466 | } |
469 | 467 |
|
| 468 | + /** |
| 469 | + * @it reports error for array passed into string input |
| 470 | + */ |
| 471 | + public function testReportsErrorForArrayPassedIntoStringInput() |
| 472 | + { |
| 473 | + |
| 474 | + $doc = ' |
| 475 | + query SetsNonNullable($value: String!) { |
| 476 | + fieldWithNonNullableStringInput(input: $value) |
| 477 | + } |
| 478 | + '; |
| 479 | + $ast = Parser::parse($doc); |
| 480 | + $variables = ['value' => [1, 2, 3]]; |
| 481 | + |
| 482 | + $expected = [ |
| 483 | + 'errors' => [[ |
| 484 | + 'message' => |
| 485 | + 'Variable "$value" got invalid value [1,2,3].' . "\n" . |
| 486 | + 'Expected type "String", found array(3).', |
| 487 | + 'category' => 'graphql', |
| 488 | + 'locations' => [ |
| 489 | + ['line' => 2, 'column' => 31] |
| 490 | + ] |
| 491 | + ]] |
| 492 | + ]; |
| 493 | + |
| 494 | + $this->assertEquals($expected, Executor::execute($this->schema(), $ast, null, null, $variables)->toArray()); |
| 495 | + } |
| 496 | + |
| 497 | + /** |
| 498 | + * @it serializing an array via GraphQLString throws TypeError |
| 499 | + */ |
| 500 | + public function testSerializingAnArrayViaGraphQLStringThrowsTypeError() |
| 501 | + { |
| 502 | + $this->setExpectedException( |
| 503 | + InvariantViolation::class, |
| 504 | + 'String cannot represent non scalar value: array(3)' |
| 505 | + ); |
| 506 | + Type::string()->serialize([1, 2, 3]); |
| 507 | + } |
| 508 | + |
470 | 509 | /** |
471 | 510 | * @it reports error for non-provided variables for non-nullable inputs |
472 | 511 | */ |
|
0 commit comments