diff --git a/src/Mappers/PorpaginasTypeMapper.php b/src/Mappers/PorpaginasTypeMapper.php index d0ea0e3..db39048 100644 --- a/src/Mappers/PorpaginasTypeMapper.php +++ b/src/Mappers/PorpaginasTypeMapper.php @@ -80,7 +80,10 @@ private function getObjectType(OutputType $subType): ObjectType if (!isset($args['limit']) && isset($args['offset'])) { throw PorpaginasMissingParameterException::missingLimit(); } - return $root->take($args['offset'], $args['limit']); + if (isset($args['limit'])) { + return $root->take($args['offset'] ?? 0, $args['limit']); + } + return $root; } ], 'count' => [ diff --git a/src/Types/InvalidTypesInUnionException.php b/src/Types/InvalidTypesInUnionException.php new file mode 100644 index 0000000..c0d1fcf --- /dev/null +++ b/src/Types/InvalidTypesInUnionException.php @@ -0,0 +1,15 @@ +name; if (!$type instanceof ObjectType) { - throw new \InvalidArgumentException('A Union type can only contain objects. Scalars, lists, etc... are not allowed.'); + throw InvalidTypesInUnionException::notObjectType(); } } parent::__construct([ diff --git a/tests/Integration/EndToEndTest.php b/tests/Integration/EndToEndTest.php index 89de7c6..b87c4a6 100644 --- a/tests/Integration/EndToEndTest.php +++ b/tests/Integration/EndToEndTest.php @@ -330,5 +330,40 @@ public function testEndToEndPorpaginas() ); $this->assertSame('In the items field of a result set, you cannot add a "offset" without also adding a "limit"', $result->toArray(Debug::RETHROW_UNSAFE_EXCEPTIONS)['errors'][0]['message']); - } + + + // Let's run a query with no limit offset + $invalidQueryString = ' + query { + getContactsIterator { + items { + name + ... on User { + email + } + } + count + } + } + '; + + $result = GraphQL::executeQuery( + $schema, + $invalidQueryString + ); + + $this->assertSame([ + 'getContactsIterator' => [ + 'items' => [ + [ + 'name' => 'Joe' + ], + [ + 'name' => 'Bill', + 'email' => 'bill@example.com' + ] + ], + 'count' => 2 + ] + ], $result->toArray(Debug::RETHROW_INTERNAL_EXCEPTIONS)['data']); } } diff --git a/tests/Mappers/StaticTypeMapperTest.php b/tests/Mappers/StaticTypeMapperTest.php index 326c121..b97a109 100644 --- a/tests/Mappers/StaticTypeMapperTest.php +++ b/tests/Mappers/StaticTypeMapperTest.php @@ -2,6 +2,7 @@ namespace TheCodingMachine\GraphQL\Controllers\Mappers; +use GraphQL\Type\Definition\StringType; use GraphQL\Type\Definition\Type; use PHPUnit\Framework\TestCase; use TheCodingMachine\GraphQL\Controllers\AbstractQueryProviderTest; @@ -81,4 +82,10 @@ public function testException3(): void $this->expectException(CannotMapTypeException::class); $this->typeMapper->mapNameToType('notExists', $this->getTypeMapper()); } + + public function testUnsupportedSubtypes(): void + { + $this->expectException(CannotMapTypeException::class); + $this->typeMapper->mapClassToType(TestObject::class, new StringType(), $this->getTypeMapper()); + } }