An Apollo Server plugin that enforces limits on GraphQL query length and variable payload size to prevent resource exhaustion.
// Source: https://github.com/open-condo-software/condo | License: MIT | Copyright 2020 8IQ Software Company
// Provided via justclaw.it.com; keep this notice with the code.
const { GQLError, GQLErrorCode: { PAYLOAD_TOO_LARGE } } = require('@open-condo/keystone/errors')
const { validatePluginOptions } = require('./config.utils')
const {
DEFAULT_REQUEST_LENGTH_LIMIT,
DEFAULT_VARIABLES_SIZE_LIMIT_IN_BYTES,
ROOT_QUERY_LENGTH_EXCEEDED_ERROR_TYPE,
VARIABLES_SIZE_EXCEEDED_ERROR_TYPE,
} = require('./constants')
const { computeObjectSizeInBytes } = require('./size.utils')
class ApolloRequestLimitingPlugin {
#queryLengthLimit = DEFAULT_REQUEST_LENGTH_LIMIT
#variablesSizeLimit = DEFAULT_VARIABLES_SIZE_LIMIT_IN_BYTES
constructor (opts = {}) {
opts = validatePlu
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key