GraphQL query cost analysis library for protecting GraphQL servers against DoS attacks by computing and limiting query cost. Version 1.0.3, stable with infrequent releases. Supports cost directives and Type Map objects for per-field cost configuration. Differentiates by integrating as a validation rule in graphql-js servers (express-graphql, Apollo Server). Requires graphql >=0.11.7 as peer dependency. Allows dynamic cost multipliers based on arguments like pagination limits.
npm install graphql-cost-analysisNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Integrates cost analysis as a validation rule in express-graphql, setting a max cost and using a cost map for the Query.users field with a multiplier.
Use import or require('...').defaultEither use cost directives in schema OR costMap in config, not both
Pass variables from request body to the costAnalysis options
Use @cost directive on schema fields for forward compatibility
const costAnalysis = require('graphql-cost-analysis').default;npm install --save graphql-cost-analysis
Pass variables: req.body.variables or graphQLParams.variables in the config