-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Access to query variables in validationRules #1777
Comments
It would be great if the variables could be accessible as a callback. |
Closing this because |
@martijnwalraven so what do you propose instead or complexity calculation for preventing DDoS of GraphQL API? |
@19majkel94 Complexity calculation is a fine solution, but using the |
@martijnwalraven But is there a better way to receive a operation DocumentNode rather than: import { parse } from "graphql";
// ...
didResolveOperation({ request, operation }) {
const operationString = request.query!.substring(
operation.loc!.start,
operation.loc!.end,
);
const query = parse(operationString);
}, |
@19majkel94 Good to hear! Yep, you should have access to |
Oh, and your current code wouldn't work with fragments, because those are not part of |
I can't use just So how to proper cut |
You should be able to use |
Great! Thanks! 😃 So here is the (I hope) final version: const query = request.operationName
? separateOperations(document)[request.operationName]
: document; |
That looks great! |
Here is a working example of |
this consumed a significant amount of our time because we assumed it ran on every request, from some clients we permit certain queries and in others we do not. could the documentation be updated to include that please https://www.apollographql.com/docs/apollo-server/api/apollo-server/#validationrules ? |
@rex-remind101 I'm sorry you were confused by our docs here! Yeah, the purpose of validation rules is to be a pure function of "operation + schema" so it doesn't work with other things. Those docs can be found at |
My feature request is partially related to #1627. Generally, I want to integrate with a
graphql-query-complexity
library that createsvalidationRules
but it need access to the query variables values and they're not present inValidationContext
ingraphql-js
. Here's how it's configured using plainexpress-graphql
middleware:In
graphql-yoga
there is a callback, like in apollo-server forcontext
:https://github.com/prisma/graphql-yoga/blob/3362b13374190fd2390594495dc08064e5ee4815/src/types.ts#L64-L77
And I think that
apollo-server
should support this kind of configuration too 😉 ChangingValidationContext
mechanism ingraphql-js
is much more complicated and the only way that the author has figured out is by makingvalidationRules
dynamic in Apollo Server:slicknode/graphql-query-complexity#7 (comment)
The text was updated successfully, but these errors were encountered: