From 66657d1e937666174a96ee881e84b998219ad62a Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Thu, 20 May 2021 22:27:36 +0200 Subject: [PATCH 1/2] apq: adapt test showing that a GET request using query parameters does not work See https://github.com/rebing/graphql-laravel/issues/780 --- tests/Unit/AutomatedPersistedQueriesTest.php | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/Unit/AutomatedPersistedQueriesTest.php b/tests/Unit/AutomatedPersistedQueriesTest.php index 98685836..88c46cb6 100644 --- a/tests/Unit/AutomatedPersistedQueriesTest.php +++ b/tests/Unit/AutomatedPersistedQueriesTest.php @@ -92,6 +92,8 @@ public function testPersistedQueryNotFound(): void public function testPersistedQueryFound(): void { + $hash = hash('sha256', trim($this->queries['examples'])); + // run query and persist $response = $this->call('GET', '/graphql', [ @@ -99,7 +101,7 @@ public function testPersistedQueryFound(): void 'extensions' => [ 'persistedQuery' => [ 'version' => 1, - 'sha256Hash' => hash('sha256', trim($this->queries['examples'])), + 'sha256Hash' => $hash, ], ], ]); @@ -111,13 +113,13 @@ public function testPersistedQueryFound(): void self::assertArrayHasKey('data', $content); self::assertEquals(['examples' => $this->data], $content['data']); - // run persisted query + // run persisted query using POST - $response = $this->call('GET', '/graphql', [ + $response = $this->call('POST', '/graphql', [ 'extensions' => [ 'persistedQuery' => [ 'version' => 1, - 'sha256Hash' => hash('sha256', trim($this->queries['examples'])), + 'sha256Hash' => $hash, ], ], ]); @@ -128,6 +130,32 @@ public function testPersistedQueryFound(): void self::assertArrayHasKey('data', $content); self::assertEquals(['examples' => $this->data], $content['data']); + + // run persisted query using GET + + $response = $this->call('GET', '/graphql?extensions={"persistedQuery":{"version":1,"sha256Hash":"' . $hash . '"}}'); + + self::assertEquals(200, $response->getStatusCode()); + + $content = $response->json(); + + $expected = [ + 'errors' => [ + [ + 'message' => 'Syntax Error: Unexpected ', + 'extensions' => [ + 'category' => 'graphql', + ], + 'locations' => [ + [ + 'line' => 1, + 'column' => 1, + ], + ], + ], + ], + ]; + self::assertEquals($expected, $content); } // This test demonstrates we don't actually check the 'version' From 50495cb7c31a80a45f62d65929c4430cd582aa42 Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Thu, 20 May 2021 22:34:22 +0200 Subject: [PATCH 2/2] apq: adapt test showing that a GET request using query parameters works in master See https://github.com/rebing/graphql-laravel/issues/780 --- tests/Unit/AutomatedPersistedQueriesTest.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/Unit/AutomatedPersistedQueriesTest.php b/tests/Unit/AutomatedPersistedQueriesTest.php index 4dde3ce0..0ec4811f 100644 --- a/tests/Unit/AutomatedPersistedQueriesTest.php +++ b/tests/Unit/AutomatedPersistedQueriesTest.php @@ -139,23 +139,8 @@ public function testPersistedQueryFound(): void $content = $response->json(); - $expected = [ - 'errors' => [ - [ - 'message' => 'Syntax Error: Unexpected ', - 'extensions' => [ - 'category' => 'graphql', - ], - 'locations' => [ - [ - 'line' => 1, - 'column' => 1, - ], - ], - ], - ], - ]; - self::assertEquals($expected, $content); + self::assertArrayHasKey('data', $content); + self::assertEquals(['examples' => $this->data], $content['data']); } // This test demonstrates we don't actually check the 'version'