How to use the graphql-rate-limit-directive.defaultPointsCalculator function in graphql-rate-limit-directive

To help you get started, we’ve selected a few graphql-rate-limit-directive examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ravangen / graphql-rate-limit / examples / points / index.js View on Github external
const pointsCalculator = (directiveArgs, obj, args, context, info) => {
  // If a specific resolver for a type and field, use custom logic
  if (info.parentType.name === 'Query' && info.fieldName === 'books') {
    // When query string `token=secret` is used, allow unlimited usage, else costs 2 for `books`
    return context.query && context.query.token === 'secret' ? 0 : 2;
  } else {
    return defaultPointsCalculator(directiveArgs, obj, args, context, info);
  }
};

graphql-rate-limit-directive

Fixed window rate-limiting directive for GraphQL. Use to limit repeated requests to queries and mutations.

MIT
Latest version published 7 months ago

Package Health Score

66 / 100
Full package analysis