Skip to content

Commit 180e429

Browse files
authored
Merge pull request #68 from overblog/fix_is_type_of
Fix isTypeOf / no empty body accepted for json request parser
2 parents e34953a + 487efcd commit 180e429

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

Generator/TypeGenerator.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,14 @@ protected function resolveTypeCode($alias)
7272
return sprintf('$container->get(\'%s\')->resolve(%s)', 'overblog_graphql.type_resolver', var_export($alias, true));
7373
}
7474

75-
/**
76-
* todo replace generateResolve in vendor after spec-april2016 is merged.
77-
*
78-
* @param array $value
79-
*
80-
* @return string
81-
*/
82-
protected function generateResolve2(array $value)
83-
{
84-
return $this->callableCallbackFromArrayValue($value, 'resolve', '$value, $args, $context, \\GraphQL\\Type\\Definition\\ResolveInfo $info');
85-
}
86-
8775
protected function generateResolve(array $value)
8876
{
8977
$accessIsSet = $this->arrayKeyExistsAndIsNotNull($value, 'access');
9078
$fieldOptions = $value;
9179
$fieldOptions['resolve'] = $this->arrayKeyExistsAndIsNotNull($fieldOptions, 'resolve') ? $fieldOptions['resolve'] : $this->defaultResolver;
9280

9381
if (!$accessIsSet || true === $fieldOptions['access']) { // access granted to this field
94-
$resolveCallback = $this->generateResolve2($fieldOptions);
82+
$resolveCallback = parent::generateResolve($fieldOptions);
9583
if ('null' === $resolveCallback) {
9684
return $resolveCallback;
9785
}
@@ -113,7 +101,7 @@ function ($value, $args, $context, %s $info) <closureUseStatements> {
113101

114102
return sprintf('function () { throw new %s(\'Access denied to this field.\'); }', $exceptionClass);
115103
} else { // wrap resolver with access
116-
$resolveCallback = $this->generateResolve2($fieldOptions);
104+
$resolveCallback = parent::generateResolve($fieldOptions);
117105
$accessChecker = $this->callableCallbackFromArrayValue($fieldOptions, 'access', '$value, $args, $context, \\GraphQL\\Type\\Definition\\ResolveInfo $info, $object');
118106
$resolveInfoClass = $this->shortenClassName('\\GraphQL\\Type\\Definition\\ResolveInfo');
119107
$argumentClass = $this->shortenClassName('\\Overblog\\GraphQLBundle\\Definition\\Argument');

Request/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ private function getParsedBody(Request $request)
5050

5151
// JSON object
5252
case static::CONTENT_TYPE_JSON:
53+
if (empty($body)) {
54+
throw new BadRequestHttpException('The request content body must not be empty when using json content type request.');
55+
}
56+
5357
$parsedBody = json_decode($body, true);
5458

5559
if (JSON_ERROR_NONE !== json_last_error()) {

Tests/Functional/Controller/GraphControllerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ public function testEndpointWithEmptyQuery()
9595
$client->getResponse()->getContent();
9696
}
9797

98+
/**
99+
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
100+
* @expectedExceptionMessage The request content body must not be empty when using json content type request.
101+
*/
102+
public function testEndpointWithEmptyJsonBodyQuery()
103+
{
104+
$client = static::createClient();
105+
$client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json']);
106+
$client->getResponse()->getContent();
107+
}
108+
109+
98110
/**
99111
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
100112
* @expectedExceptionMessage POST body sent invalid JSON

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"require": {
2525
"php": "^5.4|~7.0",
2626
"doctrine/doctrine-cache-bundle": "^1.2",
27-
"overblog/graphql-php-generator": "^0.2.2",
27+
"overblog/graphql-php-generator": "^0.3.0",
2828
"symfony/expression-language": "^2.7|^3.0",
2929
"symfony/framework-bundle": "^2.7|^3.0",
3030
"symfony/options-resolver": "^2.7|^3.0",

0 commit comments

Comments
 (0)