From 8aa6dc17a5838aa0ca938f29b5f5ce4e6cc0262c Mon Sep 17 00:00:00 2001 From: Chris Muthig Date: Sat, 3 Mar 2018 15:41:55 -0800 Subject: [PATCH 1/2] Parse operation name from operationName instead of operation --- src/Server/OperationParams.php | 4 ++-- tests/Server/RequestParsingTest.php | 18 +++++++++--------- tests/Server/RequestValidationTest.php | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Server/OperationParams.php b/src/Server/OperationParams.php index 1b9ee76..85782fe 100644 --- a/src/Server/OperationParams.php +++ b/src/Server/OperationParams.php @@ -67,7 +67,7 @@ class OperationParams 'queryid' => null, 'documentid' => null, // alias to queryid 'id' => null, // alias to queryid - 'operation' => null, + 'operationname' => null, 'variables' => null ]; @@ -84,7 +84,7 @@ class OperationParams $instance->query = $params['query']; $instance->queryId = $params['queryid'] ?: $params['documentid'] ?: $params['id']; - $instance->operation = $params['operation']; + $instance->operation = $params['operationname']; $instance->variables = $params['variables']; $instance->readOnly = (bool) $readonly; diff --git a/tests/Server/RequestParsingTest.php b/tests/Server/RequestParsingTest.php index 49f32fb..bff4da3 100644 --- a/tests/Server/RequestParsingTest.php +++ b/tests/Server/RequestParsingTest.php @@ -34,7 +34,7 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase $post = [ 'query' => $query, 'variables' => $variables, - 'operation' => $operation + 'operationName' => $operation ]; $parsed = [ 'raw' => $this->parseRawFormUrlencodedRequest($post), @@ -56,7 +56,7 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase $get = [ 'query' => $query, 'variables' => $variables, - 'operation' => $operation + 'operationName' => $operation ]; $parsed = [ 'raw' => $this->parseRawGetRequest($get), @@ -78,7 +78,7 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase $body = [ 'query' => $query, 'variables' => $variables, - 'operation' => $operation + 'operationName' => $operation ]; $parsed = [ 'raw' => $this->parseRawRequest('application/json', json_encode($body)), @@ -99,7 +99,7 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase $body = [ 'query' => $query, 'variables' => json_encode($variables), - 'operation' => $operation + 'operationName' => $operation ]; $parsed = [ 'raw' => $this->parseRawRequest('application/json', json_encode($body)), @@ -120,7 +120,7 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase $body = [ 'query' => $query, 'variables' => $variables, - 'operation' => $operation + 'operationName' => $operation ]; $parsed = [ 'raw' => $this->parseRawRequest('application/json', json_encode($body)), @@ -138,12 +138,12 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase [ 'query' => '{my query}', 'variables' => ['test' => 1, 'test2' => 2], - 'operation' => 'op' + 'operationName' => 'op' ], [ 'queryId' => 'my-query-id', 'variables' => ['test' => 1, 'test2' => 2], - 'operation' => 'op2' + 'operationName' => 'op2' ], ]; $parsed = [ @@ -153,8 +153,8 @@ class RequestParsingTest extends \PHPUnit_Framework_TestCase foreach ($parsed as $method => $parsedBody) { $this->assertInternalType('array', $parsedBody, $method); $this->assertCount(2, $parsedBody, $method); - $this->assertValidOperationParams($parsedBody[0], $body[0]['query'], null, $body[0]['variables'], $body[0]['operation'], $method); - $this->assertValidOperationParams($parsedBody[1], null, $body[1]['queryId'], $body[1]['variables'], $body[1]['operation'], $method); + $this->assertValidOperationParams($parsedBody[0], $body[0]['query'], null, $body[0]['variables'], $body[0]['operationName'], $method); + $this->assertValidOperationParams($parsedBody[1], null, $body[1]['queryId'], $body[1]['variables'], $body[1]['operationName'], $method); } } diff --git a/tests/Server/RequestValidationTest.php b/tests/Server/RequestValidationTest.php index 2a335f1..b017c12 100644 --- a/tests/Server/RequestValidationTest.php +++ b/tests/Server/RequestValidationTest.php @@ -15,7 +15,7 @@ class RequestValidationTest extends \PHPUnit_Framework_TestCase $parsedBody = OperationParams::create([ 'query' => $query, 'variables' => $variables, - 'operation' => $operation, + 'operationName' => $operation, ]); $this->assertValid($parsedBody); @@ -30,7 +30,7 @@ class RequestValidationTest extends \PHPUnit_Framework_TestCase $parsedBody = OperationParams::create([ 'queryId' => $queryId, 'variables' => $variables, - 'operation' => $operation, + 'operationName' => $operation, ]); $this->assertValid($parsedBody); @@ -40,7 +40,7 @@ class RequestValidationTest extends \PHPUnit_Framework_TestCase { $parsedBody = OperationParams::create([ 'variables' => ['foo' => 'bar'], - 'operation' => 'op', + 'operationName' => 'op', ]); $this->assertInputError( @@ -90,7 +90,7 @@ class RequestValidationTest extends \PHPUnit_Framework_TestCase { $parsedBody = OperationParams::create([ 'query' => '{my query}', - 'operation' => [] + 'operationName' => [] ]); $this->assertInputError( From 68eb325d1894fdf0e02f51cc7bf95bd5c09678bd Mon Sep 17 00:00:00 2001 From: Chris Muthig Date: Wed, 28 Mar 2018 13:55:59 -0700 Subject: [PATCH 2/2] Add a unit test covering the operationName parsing --- tests/Server/StandardServerTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Server/StandardServerTest.php b/tests/Server/StandardServerTest.php index 5a1246d..cc4adff 100644 --- a/tests/Server/StandardServerTest.php +++ b/tests/Server/StandardServerTest.php @@ -57,6 +57,23 @@ class StandardServerTest extends TestCase $this->assertPsrRequestEquals($expected, $request); } + public function testMultipleOperationPsrRequestExecution() + { + $body = [ + 'query' => 'query firstOp {fieldWithPhpError} query secondOp {f1}', + 'operationName' => 'secondOp' + ]; + + $expected = [ + 'data' => [ + 'f1' => 'f1' + ] + ]; + + $request = $this->preparePsrRequest('application/json', $body); + $this->assertPsrRequestEquals($expected, $request); + } + private function executePsrRequest($psrRequest) { $server = new StandardServer($this->config);