- policyRef:
name: graphql-static-query-complexity-flex
config:
maximumComplexity: <number> // REQUIRED, must be positive
source: <string> // OPTIONAL, default: context; values: "context" or "inline"
schema: <string> // REQUIRED when source is inline; omit when source is context
defaultFieldCost: <number> // OPTIONAL, default: 1.0, must be >= 0
blockOperation: <boolean> // OPTIONAL, default: true
rejectUnboundedLists: <boolean> // OPTIONAL, default: true
directiveName: <string> // OPTIONAL, default: cost
valueArgument: <string> // OPTIONAL, default: weight
multipliersArgument: <string> // OPTIONAL, default: multipliers
GraphQL Static Query Complexity Policy
Policy Name |
GraphQL Static Query Complexity |
Summary |
Calculates query complexity and blocks requests that exceed the defined budget |
Category |
Security |
First Omni Gateway version available |
v1.13.0 |
Returned status codes |
400 - Parse failures always trigger a 400 response. Complexity and list violations return this code only if Block request is enabled. The response includes a standard GraphQL errors object. |
Summary
The GraphQL Static Query Complexity policy estimates the complexity of each incoming GraphQL operation from your GraphQL schema and the operation text. If the estimate exceeds the configured budget or fails other checks enforced by the policy, Omni Gateway rejects the request or logs a warning and forwards it upstream.
The policy loads schema in these ways:
-
If
sourceiscontext, Omni Gateway automatically loads the schema file from the API asset in Anypoint Exchange. -
If
sourceisinline, provide the schema text directly in the policy configuration. This is required for local mode or environments not connected to Exchange.
After Omni Gateway extracts the GraphQL operation text, the policy analyzes query complexity.
If Omni Gateway can’t resolve the full operation text, as with persisted queries, it skips complexity analysis.
If a system error occurs during analysis, even if the schema loads into memory, Omni Gateway logs a warning and forwards the request instead of blocking it.
Configuring Policy Parameters
Omni Gateway Local Mode
When you apply the policy via declarative configuration files, Refer to the following policy definition and table of parameters:
| Parameter | Required | Default Value | Description |
|---|---|---|---|
|
Yes |
None |
The maximum complexity score allowed for a single query. Requests exceeding this value are blocked or logged as warnings. |
|
No |
|
|
|
No |
NA |
The schema text used for validation. Required if |
|
No |
|
The cost applied to fields that don’t have a specific complexity tag (typically @cost) in your schema file. |
|
No |
|
Specifies whether Omni Gateway blocks requests that exceed the complexity limit. If |
|
No |
|
If |
|
No |
|
The name of the complexity tag in your schema file that defines per-field costs. |
|
No |
|
The specific argument within your shema tag that defines the cost of a field. For example, in |
|
No |
|
The argument in your shcema tag that lists which field arguments multiply the cost. For example, in |
Resource Configuration Example
This example sets the maximum complexity at 250, uses default costs and tag names, and provides the schema text inline:
- policyRef:
name: graphql-static-query-complexity-flex
config:
source: inline
maximumComplexity: 250
blockOperation: true
rejectUnboundedLists: true
schema: |
directive @cost(weight: Int!, multipliers: [String!]) on FIELD_DEFINITION
type Query {
users(limit: Int): [User!]! @cost(weight: 1, multipliers: ["limit"])
version: String!
}
type User {
id: ID!
name: String!
}
Managed Omni Gateway and Omni Gateway Connected Mode
When you apply the policy from the UI, the following parameters are displayed:
| Field | Description | Default Value | Required |
|---|---|---|---|
Maximum Complexity |
The maximum allowed complexity score for a query. |
None |
Yes |
Default Field Cost |
The cost applied to fields lacking a specific complexity tag in your schema file. |
|
No |
Block request |
Specifies whether Omni Gateway blocks requests that exceed the complexity limit. If enabled, Omni Gateway blocks the request and returns a |
Enabled |
Yes |
Reject unbounded lists |
If enabled, Omni Gateway blocks queries for list fields that lack a limiting argument, such as |
Enabled |
Yes |
Directive Name |
The name of the complexity tag in your schema file that defines per-field costs. |
|
No |
Value Argument |
The argument within your complexity tag that specifies the field’s base cost. |
|
No |
Multipliers Argument |
The argument within your complexity tag that identifies which query parameters multiply the cost. For example, in \@cost(weight: 1, multipliers: ["limit"]) |
|
No |



