-
Notifications
You must be signed in to change notification settings - Fork 114
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
Overriding Middlewares #1775
Comments
Hi @spencermefford ! |
I was thinking this could be a new Lifecycle Hook (e.g If you agree, I'm keen on making a PR for it. |
There are two solutions I can see for this without introducing breaking changes. 1 - Add a new option in the module config to set whether middlewares should run from top > bottom or the other way around. By default it's top > bottom (as it's right now, so existing codebases wouldn't be affected), but other people would have the ability to specify a different order strategy. 2 - Add a new Lifecycle Hook |
@spencermefford as a side note, I was able to get this behavior by doing this: 1 - Add your auth middleware (will apply to the whole schema) Add this in your schema (typeDefs):
Then create a class with your directive logic. Here we will just append a
Create this function to configure your new directive:
Make sure you call this new function after you create the application with your modules:
Now in your middleware, check if that
I got inspired by this solution after reading #1293 |
@AlissonRS Thank you, that's a very clever solution! I think that will solve our needs for now. In the future, it would be cool to see the middleware code become a bit more configurable like mentioned above, but I'm happy with this for now. Thank you so much! |
I'm loving the middlewares concept of GraphQL Modules!
I am struggling with something though, and wonder if anyone can help. I have a set of 20 or so queries in a module that all need to use an authorization middleware, but 2 of those queries need no middleware at all. I was hoping I could set the middleware for
*
and then override the 2 that don't need it like this:However, that approach does not work since middlewares aren't coded to merge over one another. I could write out each "with auth" query and set them all to the middleware one by one, but that doesn't scale well and we're likely to forget one. I could also create a new module just for the 2 "without auth" queries, but that seems heavy since they all rely on the same types. Is there any other way I could accomplish my goal?
Thanks!
The text was updated successfully, but these errors were encountered: