Add max batch size env var

This commit is contained in:
Jake Barnby
2022-07-14 15:56:02 +12:00
parent c154ea3fc6
commit ded46774bc
3 changed files with 25 additions and 13 deletions
+3 -2
View File
@@ -79,8 +79,9 @@ _APP_USAGE_AGGREGATION_INTERVAL=30
_APP_USAGE_STATS=enabled
_APP_LOGGING_PROVIDER=
_APP_LOGGING_CONFIG=
_APP_GRAPHQL_MAX_COMPLEXITY=200
_APP_GRAPHQL_MAX_DEPTH=3
_APP_GRAPHQL_MAX_BATCH_SIZE=
_APP_GRAPHQL_MAX_COMPLEXITY=
_APP_GRAPHQL_MAX_DEPTH=
DOCKERHUB_PULL_USERNAME=
DOCKERHUB_PULL_PASSWORD=
DOCKERHUB_PULL_EMAIL=
+11 -2
View File
@@ -836,10 +836,19 @@ return [
'category' => 'GraphQL',
'description' => '',
'variables' => [
[
'name' => '_APP_GRAPHQL_MAX_BATCH_SIZE',
'description' => 'Maximum number of batched queries per request. The default value is 50.',
'introduction' => '0.17.0',
'default' => '50',
'required' => false,
'question' => '',
'filter' => ''
],
[
'name' => '_APP_GRAPHQL_MAX_COMPLEXITY',
'description' => 'Maximum complexity of a GraphQL query. The default value is 200.',
'introduction' => '0.15.0',
'introduction' => '0.17.0',
'default' => '200',
'required' => false,
'question' => '',
@@ -848,7 +857,7 @@ return [
[
'name' => '_APP_GRAPHQL_MAX_DEPTH',
'description' => 'Maximum depth of a GraphQL query. The default value is 3.',
'introduction' => '0.15.0',
'introduction' => '0.17.0',
'default' => '3',
'required' => false,
'question' => '',
+11 -9
View File
@@ -69,32 +69,34 @@ function graphqlRequest(
Type\Schema $gqlSchema
): void {
$contentType = $request->getHeader('content-type');
$maxBatchSize = App::getEnv('_APP_GRAPHQL_MAX_BATCH_SIZE', 50);
$maxComplexity = App::getEnv('_APP_GRAPHQL_MAX_QUERY_COMPLEXITY', 200);
$maxDepth = App::getEnv('_APP_GRAPHQL_MAX_QUERY_DEPTH', 3);
if ($contentType === 'application/graphql') {
if (\str_starts_with($contentType, 'application/graphql')) {
$query = parseGraphqlRequest($request);
}
if (\str_starts_with($contentType, 'multipart/form-data')) {
$query = parseMultipartRequest($query, $request);
}
if (!isset($query[0])) {
if (!\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);
}
$maxComplexity = App::getEnv('_APP_GRAPHQL_MAX_QUERY_COMPLEXITY', 200);
$maxDepth = App::getEnv('_APP_GRAPHQL_MAX_QUERY_DEPTH', 3);
$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;
} else {
$debugFlags = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE;
}
$promises = [];