Documentation
Gateway
Other Features
Security
Cost Limit

Cost Limit

Limit the complexity of a GraphQL document by using GraphQL Armor

How to use?

npm install @escape.tech/graphql-armor-cost-limit

Then, add it to your plugins:

gateway.config.ts
import {defineConfig} from '@graphql-hive/gateway';
import { costLimitPlugin } from '@escape.tech/graphql-armor-cost-limit';
 
export const gatewayConfig = defineConfig({
  plugins: () => [
    costLimitPlugin({
        // Toogle the plugin | default: true
        enabled: true,
        // Cost allowed for the query | default: 5000
        maxCost: 5000,
        // Static cost of an object | default: 2
        objectCost: 2,
        // Static cost of a field | default: 1
        scalarCost: 1,
        // Factorial applied to nested operator | default: 1.5
        depthCostFactor: 1.5,
        // Ignore the cost of introspection queries | default: true
        ignoreIntrospection: true,
        // Do you want to propagate the rejection to the client? | default: true
        propagateOnRejection: true,
 
        /* Advanced options (use here on your own risk) */
 
        // Callbacks that are ran whenever a Query is accepted
        onAccept: []
 
        // Callbacks that are ran whenever a Query is rejected
        onReject: []
    }),
  ]
});