mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
StandardServer: a bit more validation for parsed json PSR-7 request (related to #202)
This commit is contained in:
parent
9d37f4c0d9
commit
0af2fe79f2
@ -493,16 +493,21 @@ class Helper
|
||||
);
|
||||
}
|
||||
|
||||
// Try parsing ourselves if PSR-7 implementation doesn't parse JSON automatically
|
||||
if (is_array($bodyParams) && empty($bodyParams)) {
|
||||
$bodyParams = json_decode($request->getBody(), true);
|
||||
|
||||
if (json_last_error()) {
|
||||
throw new RequestError("Could not parse JSON: " . json_last_error_msg());
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($bodyParams)) {
|
||||
throw new RequestError(
|
||||
"GraphQL Server expects JSON object or array, but got " .
|
||||
Utils::printSafeJson($bodyParams)
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($bodyParams)) {
|
||||
$bodyParams = json_decode($request->getBody(), true);
|
||||
}
|
||||
} else {
|
||||
$bodyParams = $request->getParsedBody();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user