Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 3.76 KB

graphql-rate-limit.md

File metadata and controls

77 lines (53 loc) · 3.76 KB
description
This page provides the technical details of the GraphQL Rate Limit policy

GraphQL Rate Limit

{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition. {% endhint %}

Overview

The GraphQL Rate Limit policy provides basic rate limiting for GraphQL queries.

Unlike a traditional rate-limiting policy, where a weight of 1 is applied to every incoming request, the graphql-rate-limit policy calculates the cost of the GraphQL query and considers this cost to be the weight.

Functional and implementation information for the graphql-rate-limit policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs and v4 HTTP proxy APIs. It cannot be applied to v4 TCP proxy APIs or v4 message APIs. {% endhint %}

{% tabs %} {% tab title="HTTP proxy API example" %}

query { # + 1
  allPeople(first:20) { # * 20 + 1
    people { # + 1
      name # + 1
      vehicleConnection(first:10) { # * 10 + 1
        vehicles { # + 1
          id  # + 1
          name # + 1
          cargoCapacity # + 1
        }
      }
    }
  }
}

The total cost for the above GraphQL query is: ((((4 * 10 + 1) + 1) + 1) * 20 + 1) + 1 = 862 {% endtab %} {% endtabs %}

Configuration

Phases

The phases checked below are supported by the graphql-rate-limit policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsefalseonResponsefalse
onRequestContentfalseonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

The graphql-rate-limit policy can be configured with the following options:

Configuration

PropertyRequiredDescriptionTypeDefault
limittrueStatic limit on the number of GraphQL queries that can be sent.integer0
periodTimetrueTime durationInteger1
periodTimeUnittrueTime unit ("SECONDS", "MINUTES" )StringSECONDS
maxCostfalseA defined maximum cost per query. 0 means unlimited.integer0

Compatibility matrix

The following is the compatibility matrix for APIM and the graphql-rate-limit policy:

Plugin VersionSupported APIM versions
1.0+4.3+

Errors

PhaseCodeError template keyDescription
*400GRAPHQL_RATE_LIMIT_REACH_MAX_COSTWhen the query reaches the max cost
*429GRAPHQL_RATE_LIMIT_TOO_MANY_REQUESTSWhen too many requests have been made according to the rate limiting configuration