Skip to content
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

ValidationRules migration to v2 #2525

Closed
ZaninAndrea opened this issue Apr 2, 2019 · 2 comments
Closed

ValidationRules migration to v2 #2525

ZaninAndrea opened this issue Apr 2, 2019 · 2 comments

Comments

@ZaninAndrea
Copy link

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 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
      },
    }),
  ],
@trevor-scheer trevor-scheer added the 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged label Jul 8, 2019
@trevor-scheer
Copy link
Member

👋 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!

@abernix abernix removed 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged labels Jul 9, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants