diff --git a/docs/tips.rst b/docs/tips.rst index 9b18c81..25e129f 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -51,6 +51,8 @@ Create a new hydrator strategy } } +Add the type and hydrator strategy to the field: + .. code-block:: php use ApiSkeletons\Doctrine\ORM\GraphQL\Attribute as GraphQL; @@ -62,6 +64,7 @@ Create a new hydrator strategy Add the new type and hydrator strategy to the Driver: .. code-block:: php + use ApiSkeletons\Doctrine\ORM\GraphQL\Hydrator\HydratorContainer; use ApiSkeletons\Doctrine\ORM\GraphQL\Type\TypeContainer; use App\GraphQL\Hydrator\Strategy\CsvString; diff --git a/docs/types.rst b/docs/types.rst index 090e770..9c4f255 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -115,7 +115,7 @@ input type. Custom Types ============ -If your schema has a ``timestamp`` type, that data type is not suppored +If your schema has a ``timestamp`` type, that data type is not supported by this library. But adding the type is just a matter of creating a new Timestamp type extending ``GraphQL\Type\Definition\ScalarType`` then adding the type to the type container. @@ -125,6 +125,7 @@ the type to the type container. $driver->get(TypeContainer::class) ->set('timestamp', fn() => new Timestamp()); +See also `Serve a CSV Field as a GraphQL Array `_. .. role:: raw-html(raw) :format: html diff --git a/test/Feature/Type/BetweenTest.php b/test/Feature/Type/BetweenTest.php index 6879a76..0cbd094 100644 --- a/test/Feature/Type/BetweenTest.php +++ b/test/Feature/Type/BetweenTest.php @@ -23,13 +23,7 @@ public function testTwoFilterSetsEachWithBetweenButDifferentOtherwiseFetchesBetw 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'artist' => [ - 'type' => $driver->type(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/BlobTest.php b/test/Feature/Type/BlobTest.php index e2503d4..8eb355f 100644 --- a/test/Feature/Type/BlobTest.php +++ b/test/Feature/Type/BlobTest.php @@ -94,13 +94,7 @@ public function testBlobQuery(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/CustomTypeTest.php b/test/Feature/Type/CustomTypeTest.php index 6d4bc3d..0edf490 100644 --- a/test/Feature/Type/CustomTypeTest.php +++ b/test/Feature/Type/CustomTypeTest.php @@ -29,13 +29,7 @@ public function testCustomFieldType(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typeTest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typeTest' => $driver->completeConnection(TypeTest::class), ], ]), ]); @@ -62,17 +56,17 @@ public function testCustomFieldTypeArray(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typeTest' => $driver->completeConnection(TypeTest::class), + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); - $query = '{ typeTest { edges { node { testText } } } }'; + $query = '{ typetest { edges { node { testText } } } }'; $result = GraphQL::executeQuery($schema, $query); $data = $result->toArray()['data']; - $this->assertIsArray($data['typeTest']['edges'][0]['node']['testText']); - $this->assertCount(3, $data['typeTest']['edges'][0]['node']['testText']); + $this->assertIsArray($data['typetest']['edges'][0]['node']['testText']); + $this->assertCount(3, $data['typetest']['edges'][0]['node']['testText']); } } diff --git a/test/Feature/Type/DateImmutableTest.php b/test/Feature/Type/DateImmutableTest.php index b8bebd8..15631cf 100644 --- a/test/Feature/Type/DateImmutableTest.php +++ b/test/Feature/Type/DateImmutableTest.php @@ -67,13 +67,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); @@ -120,13 +114,7 @@ public function testBetweenLiteral(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); @@ -165,13 +153,7 @@ public function testInvalidLiteralValue(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/DateTest.php b/test/Feature/Type/DateTest.php index 2ccd95f..0ca1d1c 100644 --- a/test/Feature/Type/DateTest.php +++ b/test/Feature/Type/DateTest.php @@ -68,13 +68,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); @@ -120,13 +114,7 @@ public function testBetweenLiteral(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); @@ -165,13 +153,7 @@ public function testInvalidLiteralValue(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/DateTimeImmutableTest.php b/test/Feature/Type/DateTimeImmutableTest.php index 1bdce67..c846377 100644 --- a/test/Feature/Type/DateTimeImmutableTest.php +++ b/test/Feature/Type/DateTimeImmutableTest.php @@ -62,13 +62,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/DateTimeTZImmutableTest.php b/test/Feature/Type/DateTimeTZImmutableTest.php index 9d12cb6..b9e7b8b 100644 --- a/test/Feature/Type/DateTimeTZImmutableTest.php +++ b/test/Feature/Type/DateTimeTZImmutableTest.php @@ -62,13 +62,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/DateTimeTZTest.php b/test/Feature/Type/DateTimeTZTest.php index 294eff3..9ab3b0d 100644 --- a/test/Feature/Type/DateTimeTZTest.php +++ b/test/Feature/Type/DateTimeTZTest.php @@ -60,13 +60,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); @@ -78,8 +72,5 @@ public function testBetween(): void $data = $result->toArray()['data']; $this->assertTrue(true); - -// $this->assertEquals(1, count($data['typetest']['edges'])); -// $this->assertEquals(1, $data['typetest']['edges'][0]['node']['id']); } } diff --git a/test/Feature/Type/DateTimeTest.php b/test/Feature/Type/DateTimeTest.php index 5f10c76..9fa7da3 100644 --- a/test/Feature/Type/DateTimeTest.php +++ b/test/Feature/Type/DateTimeTest.php @@ -62,13 +62,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/JsonTest.php b/test/Feature/Type/JsonTest.php index cc3ad98..5fe1b22 100644 --- a/test/Feature/Type/JsonTest.php +++ b/test/Feature/Type/JsonTest.php @@ -62,13 +62,7 @@ public function testContains(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/PageInfoTest.php b/test/Feature/Type/PageInfoTest.php index 1304a85..244700b 100644 --- a/test/Feature/Type/PageInfoTest.php +++ b/test/Feature/Type/PageInfoTest.php @@ -22,14 +22,7 @@ public function testPageInfo(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); @@ -73,14 +66,7 @@ public function testPageInfoHasNextPage(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); @@ -113,14 +99,7 @@ public function testPageInfoHasPreviousPage(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); diff --git a/test/Feature/Type/PaginationTest.php b/test/Feature/Type/PaginationTest.php index 324a16f..c6def66 100644 --- a/test/Feature/Type/PaginationTest.php +++ b/test/Feature/Type/PaginationTest.php @@ -22,14 +22,7 @@ public function testFirst(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); @@ -64,14 +57,7 @@ public function testAfter(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); @@ -107,14 +93,7 @@ public function testLast(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); @@ -150,14 +129,7 @@ public function testBefore(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); @@ -193,14 +165,7 @@ public function testNegativeOffset(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'performance' => [ - 'type' => $driver->connection(Performance::class), - 'args' => [ - 'filter' => $driver->filter(Performance::class), - 'pagination' => $driver->pagination(), - ], - 'resolve' => $driver->resolve(Performance::class), - ], + 'performance' => $driver->completeConnection(Performance::class), ], ]), ]); diff --git a/test/Feature/Type/TimeImmutableTest.php b/test/Feature/Type/TimeImmutableTest.php index 1806f3a..357833a 100644 --- a/test/Feature/Type/TimeImmutableTest.php +++ b/test/Feature/Type/TimeImmutableTest.php @@ -61,13 +61,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]); diff --git a/test/Feature/Type/TimeTest.php b/test/Feature/Type/TimeTest.php index dc451eb..95b3906 100644 --- a/test/Feature/Type/TimeTest.php +++ b/test/Feature/Type/TimeTest.php @@ -60,13 +60,7 @@ public function testBetween(): void 'query' => new ObjectType([ 'name' => 'query', 'fields' => [ - 'typetest' => [ - 'type' => $driver->connection(TypeTest::class), - 'args' => [ - 'filter' => $driver->filter(TypeTest::class), - ], - 'resolve' => $driver->resolve(TypeTest::class), - ], + 'typetest' => $driver->completeConnection(TypeTest::class), ], ]), ]);