-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Allow skipping complexity check in Harden Plugin #3340
base: minor
Are you sure you want to change the base?
Feat: Allow skipping complexity check in Harden Plugin #3340
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@michaelbromley Not sure why tests are failing, HardenPlugin doesn't seem to be included in any e2e tests. Someone else broke the minor branch maybe? |
const maxQueryComplexity = this.options.maxQueryComplexity ?? 1000; | ||
return { | ||
didResolveOperation: async ({ request, document }) => { | ||
if (isAdminApi(schema)) { | ||
if (this.options.skip?.(ctx)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if this supported Awaitable<boolean>
in addition to boolean
. Supporting promises would allow developers to include external resources, such as making a third-party validation request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I purposely did not do that, because it can have severe performance impact if you do anything async in every request.
But I guess we can move that responsibility to the consumer.... Let me add it.
Quality Gate passedIssues Measures |
Description
We are using the Harden Plugin, but would like to be able to skip the complexity check for storefront SSR builds.
This PR introduces an optional
skip
function, inspired by express-rate-limit, that allows the consumer to skip certain requests.Screenshots below we're tested with the following config:
This skips the complexity check when the header
x-skip-complexity
is present. In production use, you would check for a token or something.Breaking changes
No
Screenshots
Complex query without header
The same complex query with custom header
And, another test without a
skip
function specified.Checklist
📌 Always:
👍 Most of the time: