From 244ec66ecc0677d25ad2d958baed7de50e551043 Mon Sep 17 00:00:00 2001 From: chriszarate Date: Tue, 11 Dec 2018 22:58:57 -0500 Subject: [PATCH] Allow extensions to be provided in GET request. --- src/Server/OperationParams.php | 15 +++++++++++---- tests/Server/RequestParsingTest.php | 12 +++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Server/OperationParams.php b/src/Server/OperationParams.php index 0d14614..6d2cfd1 100644 --- a/src/Server/OperationParams.php +++ b/src/Server/OperationParams.php @@ -89,11 +89,18 @@ class OperationParams $params['variables'] = null; } - if (is_string($params['variables'])) { - $tmp = json_decode($params['variables'], true); - if (! json_last_error()) { - $params['variables'] = $tmp; + // Some parameters could be provided as serialized JSON. + foreach (['extensions', 'variables'] as $param) { + if (! is_string($params[$param])) { + continue; } + + $tmp = json_decode($params[$param], true); + if (json_last_error()) { + continue; + } + + $params[$param] = $tmp; } $instance->query = $params['query']; diff --git a/tests/Server/RequestParsingTest.php b/tests/Server/RequestParsingTest.php index cf2e9c5..9de6eab 100644 --- a/tests/Server/RequestParsingTest.php +++ b/tests/Server/RequestParsingTest.php @@ -293,14 +293,16 @@ class RequestParsingTest extends TestCase } } - public function testParsesVariablesAsJSON() : void + public function testParsesParamsAsJSON() : void { - $query = '{my query}'; - $variables = ['test' => 1, 'test2' => 2]; - $operation = 'op'; + $query = '{my query}'; + $variables = ['test1' => 1, 'test2' => 2]; + $extensions = ['test3' => 3, 'test4' => 4]; + $operation = 'op'; $body = [ 'query' => $query, + 'extensions' => json_encode($extensions), 'variables' => json_encode($variables), 'operationName' => $operation, ]; @@ -309,7 +311,7 @@ class RequestParsingTest extends TestCase 'psr' => $this->parsePsrRequest('application/json', json_encode($body)), ]; 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); } }