1
0
Fork 0
mirror of synced 2024-10-01 17:58:02 +13:00

Add too many queries exception

This commit is contained in:
Jake Barnby 2022-07-14 15:57:34 +12:00
parent ded46774bc
commit 4ee7f80433
2 changed files with 11 additions and 5 deletions

View file

@ -514,7 +514,12 @@ return [
], ],
Exception::GRAPHQL_NO_QUERY => [ Exception::GRAPHQL_NO_QUERY => [
'name' => Exception::GRAPHQL_NO_QUERY, 'name' => Exception::GRAPHQL_NO_QUERY,
'description' => 'Query is required and can be provided via parameter or as the raw body if the content-type header is application/graphql.', 'description' => 'Query is required.',
'code' => 400,
],
Exception::GRAPHQL_TOO_MANY_QUERIES => [
'name' => Exception::GRAPHQL_TOO_MANY_QUERIES,
'description' => 'Too many queries have been sent in the same request.',
'code' => 400, 'code' => 400,
], ],
]; ];

View file

@ -79,14 +79,15 @@ function graphqlRequest(
if (\str_starts_with($contentType, 'multipart/form-data')) { if (\str_starts_with($contentType, 'multipart/form-data')) {
$query = parseMultipartRequest($query, $request); $query = parseMultipartRequest($query, $request);
} }
if (!\isset($query[0])) { if (!empty($query) && !isset($query[0])) {
$query = [$query]; $query = [$query];
} }
if (\empty($query)) { if (empty($query)) {
throw new Exception('No query supplied.', 400, Exception::GRAPHQL_NO_QUERY); throw new Exception('No query supplied.', 400, Exception::GRAPHQL_NO_QUERY);
} }
if (\count($query) > $maxBatchSize) { if (\count($query) > $maxBatchSize) {
throw new Exception('Too many queries in batch.', 400, Exception::GRAPHQL_TOO_MANY_QUERIES); throw new Exception('Too many queries.', 400, Exception::GRAPHQL_TOO_MANY_QUERIES);
}
} }
$debugFlags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE; $debugFlags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;