You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
graphql-cost-analysis allows an onComplete callback which we use to ratelimit the queries of each user, unfortunately with v2 apollo moved away from the middleware sintax and thus validationRules cannot access the express req nor the context anymore, so we cannot ratelimit the various users with the cost calculated by graphql-cost-analysis.
Is there a way to implement the same behaviour with Apollo Server Express v2?
Code used in previous apollo version:
validationRules: ({ req })=>[costAnalysis({variables: req.body.variables,maximumCost: 500,onComplete: cost=>{if(cost<MAX_COST)req.rateLimitCost(cost+1)// function defined when reading the authentication token},}),],
The text was updated successfully, but these errors were encountered:
👋 Hey @ZaninAndrea, I'm going to close this since this doesn't appear to be a bug with Apollo Server, but rather a question about how to use it or one of its components.
Rather than asking it here in GitHub Issues — where efforts are focused on fixing bugs and adding new features — I'd ask that you take this question to the Apollo Server channel within the Apollo community on Spectrum.chat where there are community members who might be able to relate to a similar problem, or might be able to help you out more interactively. Thanks for your understanding!
In a medium article on the apollo publication (https://blog.apollographql.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b) the suggested solution for mitigating malicious queries was graphql-cost-analysis.
graphql-cost-analysis
allows anonComplete
callback which we use to ratelimit the queries of each user, unfortunately with v2 apollo moved away from the middleware sintax and thusvalidationRules
cannot access the expressreq
nor thecontext
anymore, so we cannot ratelimit the various users with the cost calculated bygraphql-cost-analysis
.Is there a way to implement the same behaviour with Apollo Server Express v2?
Code used in previous apollo version:
The text was updated successfully, but these errors were encountered: