Apollo server/client compatibility. Look for queryid in extensions.

This commit is contained in:
chriszarate 2018-12-01 18:49:23 -05:00
parent b2cea8b538
commit 63b4e3f0a4
2 changed files with 31 additions and 0 deletions

View File

@ -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;
}

View File

@ -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 = [