diff --git a/src/Server/OperationParams.php b/src/Server/OperationParams.php index 8085d1e..a76f86e 100644 --- a/src/Server/OperationParams.php +++ b/src/Server/OperationParams.php @@ -95,6 +95,11 @@ class OperationParams $instance->variables = $params['variables']; $instance->readOnly = (bool) $readonly; + // Apollo server/client compatibility: look for the queryid in extensions + if (isset($params['extensions']['persistedQuery']['sha256Hash']) && empty($instance->query) && empty($instance->queryid)) { + $instance->queryId = $params['extensions']['persistedQuery']['sha256Hash']; + } + return $instance; } diff --git a/tests/Server/RequestParsingTest.php b/tests/Server/RequestParsingTest.php index b6c73d6..75412b1 100644 --- a/tests/Server/RequestParsingTest.php +++ b/tests/Server/RequestParsingTest.php @@ -333,6 +333,32 @@ class RequestParsingTest extends TestCase } } + public function testParsesApolloPersistedQueryJSONRequest() : void + { + $queryId = 'my-query-id'; + $extensions = [ + 'persistedQuery' => [ + 'sha256Hash' => $queryId, + ], + ]; + $variables = ['test' => 1, 'test2' => 2]; + $operation = 'op'; + + $body = [ + 'extensions' => $extensions, + 'variables' => $variables, + 'operationName' => $operation, + ]; + $parsed = [ + 'raw' => $this->parseRawRequest('application/json', json_encode($body)), + 'psr' => $this->parsePsrRequest('application/json', json_encode($body)), + ]; + foreach ($parsed as $method => $parsedBody) { + self::assertValidOperationParams($parsedBody, null, $queryId, $variables, $operation, $method); + self::assertFalse($parsedBody->isReadOnly(), $method); + } + } + public function testParsesBatchJSONRequest() : void { $body = [