Skip to content

Commit 5888470

Browse files
alanpoulainabluchet
authored andcommitted
IterableType implements the BC in the LeafType interface
1 parent 880d56e commit 5888470

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/GraphQl/Type/Definition/IterableType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Core\GraphQl\Type\Definition;
1515

1616
use GraphQL\Error\Error;
17-
use GraphQL\Error\InvariantViolation;
1817
use GraphQL\Language\AST\BooleanValueNode;
1918
use GraphQL\Language\AST\FloatValueNode;
2019
use GraphQL\Language\AST\IntValueNode;
@@ -44,7 +43,7 @@ public function serialize($value)
4443
{
4544
// is_iterable
4645
if (!(\is_array($value) || $value instanceof \Traversable)) {
47-
throw new InvariantViolation(sprintf('Iterable cannot represent non iterable value: %s', Utils::printSafe($value)));
46+
throw new Error(sprintf('Iterable cannot represent non iterable value: %s', Utils::printSafe($value)));
4847
}
4948

5049
return $value;
@@ -66,13 +65,14 @@ public function parseValue($value)
6665
/**
6766
* {@inheritdoc}
6867
*/
69-
public function parseLiteral($valueNode)
68+
public function parseLiteral($valueNode, array $variables = null)
7069
{
7170
if ($valueNode instanceof ObjectValueNode || $valueNode instanceof ListValueNode) {
7271
return $this->parseIterableLiteral($valueNode);
7372
}
7473

75-
return null;
74+
// Intentionally without message, as all information already in wrapped Exception
75+
throw new \Exception();
7676
}
7777

7878
/**

tests/GraphQl/Type/Definition/IterableTypeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use ApiPlatform\Core\GraphQl\Type\Definition\IterableType;
1717
use GraphQL\Error\Error;
18-
use GraphQL\Error\InvariantViolation;
1918
use GraphQL\Language\AST\BooleanValueNode;
2019
use GraphQL\Language\AST\FloatValueNode;
2120
use GraphQL\Language\AST\IntValueNode;
@@ -36,8 +35,8 @@ public function testSerialize()
3635
{
3736
$iterableType = new IterableType();
3837

39-
$this->expectException(InvariantViolation::class);
40-
$this->expectExceptionMessage('Iterable cannot represent non iterable value: "foo"');
38+
$this->expectException(Error::class);
39+
$this->expectExceptionMessage('Iterable cannot represent non iterable value: foo');
4140

4241
$iterableType->serialize('foo');
4342

@@ -60,7 +59,8 @@ public function testParseLiteral()
6059
{
6160
$iterableType = new IterableType();
6261

63-
$this->assertNull($iterableType->parseLiteral(new IntValueNode(['value' => 1])));
62+
$this->expectException(\Exception::class);
63+
$iterableType->parseLiteral(new IntValueNode(['value' => 1]));
6464

6565
$listValueNode = new ListValueNode(['values' => []]);
6666
$this->assertEquals([], $iterableType->parseLiteral($listValueNode));

0 commit comments

Comments
 (0)