1
0
Fork 0
mirror of synced 2024-06-28 19:20:25 +12: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 => [
'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,
],
];

View file

@ -79,21 +79,22 @@ function graphqlRequest(
if (\str_starts_with($contentType, 'multipart/form-data')) {
$query = parseMultipartRequest($query, $request);
}
if (!\isset($query[0])) {
if (!empty($query) && !isset($query[0])) {
$query = [$query];
}
if (\empty($query)) {
if (empty($query)) {
throw new Exception('No query supplied.', 400, Exception::GRAPHQL_NO_QUERY);
}
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;
$validations = GraphQL::getStandardValidationRules();
$validations[] = new QueryComplexity($maxComplexity);
$validations[] = new QueryDepth($maxDepth);
if (App::isProduction()) {
$validations[] = new DisableIntrospection();
$debugFlags = DebugFlag::NONE;