From 44a0bee3fe88be627864dbcacc0cee62769ff5cb Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sat, 4 Jan 2025 23:55:41 -0700 Subject: [PATCH 1/3] Reviewed Type tests --- docs/tips.rst | 2 + docs/types.rst | 3 +- test/Feature/Type/BetweenTest.php | 8 +--- test/Feature/Type/BlobTest.php | 8 +--- test/Feature/Type/CustomTypeTest.php | 16 +++---- test/Feature/Type/DateImmutableTest.php | 24 ++-------- test/Feature/Type/DateTest.php | 24 ++-------- test/Feature/Type/DateTimeImmutableTest.php | 8 +--- test/Feature/Type/DateTimeTZImmutableTest.php | 8 +--- test/Feature/Type/DateTimeTZTest.php | 11 +---- test/Feature/Type/DateTimeTest.php | 8 +--- test/Feature/Type/JsonTest.php | 8 +--- test/Feature/Type/PageInfoTest.php | 27 ++--------- test/Feature/Type/PaginationTest.php | 45 +++---------------- test/Feature/Type/TimeImmutableTest.php | 8 +--- test/Feature/Type/TimeTest.php | 8 +--- 16 files changed, 32 insertions(+), 184 deletions(-) diff --git a/docs/tips.rst b/docs/tips.rst index 9b18c813..d7185d6d 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; diff --git a/docs/types.rst b/docs/types.rst index 090e7704..9c4f255c 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 6879a76d..0cbd094e 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 e2503d46..8eb355f0 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 6d4bc3d5..0edf4905 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 b8bebd88..15631cfc 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 2ccd95fd..0ca1d1ce 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 1bdce67a..c846377d 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 9d12cb6c..b9e7b8b0 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 294eff33..9ab3b0dc 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 5f10c76f..9fa7da33 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 cc3ad985..5fe1b22c 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 1304a85f..244700b3 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 324a16f5..c6def66e 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 1806f3ac..357833a4 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 dc451ebd..95b3906a 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), ], ]), ]); From cdd72bbb8b070455d3699ed25a252d2493623733 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 5 Jan 2025 00:01:34 -0700 Subject: [PATCH 2/3] Fix tips code block --- docs/tips.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/tips.rst b/docs/tips.rst index d7185d6d..25e129f5 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -64,6 +64,7 @@ Add the type and hydrator strategy to the field: 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; From 88fcd306e60f9d11acbc8c19e177f5716393cb9a Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Sun, 5 Jan 2025 00:10:05 -0700 Subject: [PATCH 3/3] Added style sheet to docs to set table width --- docs/_static/styles.css | 8 ++++++++ docs/conf.py | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 docs/_static/styles.css diff --git a/docs/_static/styles.css b/docs/_static/styles.css new file mode 100644 index 00000000..796ea929 --- /dev/null +++ b/docs/_static/styles.css @@ -0,0 +1,8 @@ +table { + width: 100%; + border-collapse: collapse; /* Optional: collapses borders for a cleaner look */ +} +th, td { + border: 1px solid black; /* Optional: adds borders to cells */ + padding: 5px; /* Optional: adds padding to cells */ +} diff --git a/docs/conf.py b/docs/conf.py index 4888e5e0..c5206baf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,6 +19,9 @@ exclude_patterns = ['_build'] html_static_path = ['_static'] +html_css_files = [ + 'styles.css', +] ##### Guzzle sphinx theme