From 404feba721f20accb6618dc60faa9d7c2f26c107 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Wed, 12 Oct 2016 17:50:37 +0200 Subject: [PATCH 1/2] Fix isTypeOf --- Generator/TypeGenerator.php | 16 ++-------------- composer.json | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Generator/TypeGenerator.php b/Generator/TypeGenerator.php index 51eeb13e1..39d70606e 100644 --- a/Generator/TypeGenerator.php +++ b/Generator/TypeGenerator.php @@ -72,18 +72,6 @@ protected function resolveTypeCode($alias) return sprintf('$container->get(\'%s\')->resolve(%s)', 'overblog_graphql.type_resolver', var_export($alias, true)); } - /** - * todo replace generateResolve in vendor after spec-april2016 is merged. - * - * @param array $value - * - * @return string - */ - protected function generateResolve2(array $value) - { - return $this->callableCallbackFromArrayValue($value, 'resolve', '$value, $args, $context, \\GraphQL\\Type\\Definition\\ResolveInfo $info'); - } - protected function generateResolve(array $value) { $accessIsSet = $this->arrayKeyExistsAndIsNotNull($value, 'access'); @@ -91,7 +79,7 @@ protected function generateResolve(array $value) $fieldOptions['resolve'] = $this->arrayKeyExistsAndIsNotNull($fieldOptions, 'resolve') ? $fieldOptions['resolve'] : $this->defaultResolver; if (!$accessIsSet || true === $fieldOptions['access']) { // access granted to this field - $resolveCallback = $this->generateResolve2($fieldOptions); + $resolveCallback = parent::generateResolve($fieldOptions); if ('null' === $resolveCallback) { return $resolveCallback; } @@ -113,7 +101,7 @@ function ($value, $args, $context, %s $info) { return sprintf('function () { throw new %s(\'Access denied to this field.\'); }', $exceptionClass); } else { // wrap resolver with access - $resolveCallback = $this->generateResolve2($fieldOptions); + $resolveCallback = parent::generateResolve($fieldOptions); $accessChecker = $this->callableCallbackFromArrayValue($fieldOptions, 'access', '$value, $args, $context, \\GraphQL\\Type\\Definition\\ResolveInfo $info, $object'); $resolveInfoClass = $this->shortenClassName('\\GraphQL\\Type\\Definition\\ResolveInfo'); $argumentClass = $this->shortenClassName('\\Overblog\\GraphQLBundle\\Definition\\Argument'); diff --git a/composer.json b/composer.json index 283fd511f..e93631b73 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require": { "php": "^5.4|~7.0", "doctrine/doctrine-cache-bundle": "^1.2", - "overblog/graphql-php-generator": "^0.2.2", + "overblog/graphql-php-generator": "^0.3.0", "symfony/expression-language": "^2.7|^3.0", "symfony/framework-bundle": "^2.7|^3.0", "symfony/options-resolver": "^2.7|^3.0", From 487efcdfcd2d5390136e9c365b0535f5855adb28 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Thu, 13 Oct 2016 16:11:32 +0200 Subject: [PATCH 2/2] No empty body accepted for json request parser --- Request/Parser.php | 4 ++++ Tests/Functional/Controller/GraphControllerTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Request/Parser.php b/Request/Parser.php index 6bffd78e6..41cfd7435 100644 --- a/Request/Parser.php +++ b/Request/Parser.php @@ -50,6 +50,10 @@ private function getParsedBody(Request $request) // JSON object case static::CONTENT_TYPE_JSON: + if (empty($body)) { + throw new BadRequestHttpException('The request content body must not be empty when using json content type request.'); + } + $parsedBody = json_decode($body, true); if (JSON_ERROR_NONE !== json_last_error()) { diff --git a/Tests/Functional/Controller/GraphControllerTest.php b/Tests/Functional/Controller/GraphControllerTest.php index 4307240ac..18c0189c8 100644 --- a/Tests/Functional/Controller/GraphControllerTest.php +++ b/Tests/Functional/Controller/GraphControllerTest.php @@ -95,6 +95,18 @@ public function testEndpointWithEmptyQuery() $client->getResponse()->getContent(); } + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException + * @expectedExceptionMessage The request content body must not be empty when using json content type request. + */ + public function testEndpointWithEmptyJsonBodyQuery() + { + $client = static::createClient(); + $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json']); + $client->getResponse()->getContent(); + } + + /** * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * @expectedExceptionMessage POST body sent invalid JSON