Skip to content

Commit 39682ac

Browse files
committed
Adding failing test for nullable fields returning a Porpaginas Result
1 parent 602bfa6 commit 39682ac

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/Fixtures/Integration/Controllers/ContactController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
use Porpaginas\Arrays\ArrayResult;
8+
use Porpaginas\Result;
89
use TheCodingMachine\GraphQLite\Annotations\Mutation;
910
use TheCodingMachine\GraphQLite\Annotations\Query;
1011
use TheCodingMachine\GraphQLite\Annotations\Security;
@@ -78,4 +79,15 @@ public function getOtherContact(): Contact
7879
{
7980
return new Contact('Joe');
8081
}
82+
83+
/**
84+
* Test that we can have nullable results from Porpaginas.
85+
*
86+
* @Query()
87+
* @return Result|Contact[]|null
88+
*/
89+
public function getNullableResult(): ?Result
90+
{
91+
return null;
92+
}
8193
}

tests/Integration/EndToEndTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,4 +1545,30 @@ public function testInputOutputNameConflict(): void
15451545

15461546
$schema->validate();
15471547
}
1548+
1549+
public function testNullableResult(){
1550+
/**
1551+
* @var Schema $schema
1552+
*/
1553+
$schema = $this->mainContainer->get(Schema::class);
1554+
1555+
$queryString = '
1556+
query {
1557+
nullableResult {
1558+
count
1559+
}
1560+
}
1561+
';
1562+
1563+
$result = GraphQL::executeQuery(
1564+
$schema,
1565+
$queryString
1566+
);
1567+
$resultArray = $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS);
1568+
if (isset($resultArray['errors']) || !isset($resultArray['data'])) {
1569+
$this->fail('Expected a successful answer. Got '.json_encode($resultArray, JSON_PRETTY_PRINT));
1570+
}
1571+
$this->assertNull($resultArray['data']['getNullableResult']);
1572+
}
1573+
15481574
}

0 commit comments

Comments
 (0)