graphql / express-graphql

Create a GraphQL HTTP server with Express.
MIT License
6.34k stars 537 forks source link

depth-limit #771

Open kingrupam opened 3 years ago

kingrupam commented 3 years ago

how to Limit query depth using express-graphql

notrab commented 3 years ago

@kingrupam something like the following should do it:

const depthLimit = require('graphql-depth-limit')
const express = require('express')
const graphqlHTTP = require('express-graphql')

const app = express()

const schema = `...`

app.use('/graphql', graphqlHTTP((req, res) => ({
  schema,
  validationRules: [ depthLimit(7) ]
})))

app.listen(4000)