Merge pull request #418 from Quartz/improvement/apollo-compatible-persisted-queries

Allow extensions to be provided in GET request.
This commit is contained in:
Vladimir Razuvaev 2018-12-31 13:05:09 +03:00 committed by GitHub
commit 5ac3eeab18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -89,11 +89,18 @@ class OperationParams
$params['variables'] = null; $params['variables'] = null;
} }
if (is_string($params['variables'])) { // Some parameters could be provided as serialized JSON.
$tmp = json_decode($params['variables'], true); foreach (['extensions', 'variables'] as $param) {
if (! json_last_error()) { if (! is_string($params[$param])) {
$params['variables'] = $tmp; continue;
} }
$tmp = json_decode($params[$param], true);
if (json_last_error()) {
continue;
}
$params[$param] = $tmp;
} }
$instance->query = $params['query']; $instance->query = $params['query'];

View File

@ -293,14 +293,16 @@ class RequestParsingTest extends TestCase
} }
} }
public function testParsesVariablesAsJSON() : void public function testParsesParamsAsJSON() : void
{ {
$query = '{my query}'; $query = '{my query}';
$variables = ['test' => 1, 'test2' => 2]; $variables = ['test1' => 1, 'test2' => 2];
$extensions = ['test3' => 3, 'test4' => 4];
$operation = 'op'; $operation = 'op';
$body = [ $body = [
'query' => $query, 'query' => $query,
'extensions' => json_encode($extensions),
'variables' => json_encode($variables), 'variables' => json_encode($variables),
'operationName' => $operation, 'operationName' => $operation,
]; ];
@ -309,7 +311,7 @@ class RequestParsingTest extends TestCase
'psr' => $this->parsePsrRequest('application/json', json_encode($body)), 'psr' => $this->parsePsrRequest('application/json', json_encode($body)),
]; ];
foreach ($parsed as $method => $parsedBody) { foreach ($parsed as $method => $parsedBody) {
self::assertValidOperationParams($parsedBody, $query, null, $variables, $operation, null, $method); self::assertValidOperationParams($parsedBody, $query, null, $variables, $operation, $extensions, $method);
self::assertFalse($parsedBody->isReadOnly(), $method); self::assertFalse($parsedBody->isReadOnly(), $method);
} }
} }