Query Depth Limiting
Sometimes persisted operations cannot be used. E.g. if you are building an API that is used by third party users. However, we can still apply some protection.
The maxDepth plugin allows a maximum nesting level an operation is allowed to have.
Getting Started
Install the plugin first;
yarn add @escape.tech/graphql-armor-max-depthThen configure it in your .meshrc.yml file.
plugins:
- maxDepthPlugin:
n: 10 # Number of depth allowedThis can prevent malicious API users executing GraphQL operations with deeply nested selection sets. You need to tweak the maximum depth an operation selection set is allowed to have based on your schema and needs, as it could vary between users.
A handy tool for analyzing your existing GraphQL operations and finding the best defaults is
graphql-inspector (opens in a new tab).
Learn more about graphql-inspector audit
here (opens in a new tab).