You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

graphql-depth-limit

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-depth-limit

Limit the complexity of your GraphQL queries based on depth.

1.1.0
latest
Source
npm
Version published
Weekly downloads
721K
-7.16%
Maintainers
1
Weekly downloads
 
Created

What is graphql-depth-limit?

The graphql-depth-limit npm package is used to limit the depth of GraphQL queries. This is useful for preventing deeply nested queries that can lead to performance issues or denial of service attacks.

What are graphql-depth-limit's main functionalities?

Limit Query Depth

This feature allows you to set a maximum depth for GraphQL queries. In this example, the query depth is limited to 5 levels. If a query exceeds this depth, it will be rejected.

const depthLimit = require('graphql-depth-limit');
const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () => 'Hello world!',
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  validationRules: [depthLimit(5)], // Limit query depth to 5
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

Other packages similar to graphql-depth-limit

Keywords

graphql

FAQs

Package last updated on 09 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts