-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Middleware not called for GraphQL request in 7.4.2 (upgrade from 7.0.1) #5320
Comments
Please provide a minimum reproduction. |
Repo: https://github.com/manju-reddys/nest_7.4.2_gql, Please see the readme for more info |
1 similar comment
Repo: https://github.com/manju-reddys/nest_7.4.2_gql, Please see the readme for more info |
I get the feeling this is happening due to how Fastify v3 handles middleware vs how Fastify v2 used to handle it. As no changes were made to the GQL specific code, it's hard to say where the break really is. The ApolloServer is essentially registered as a middleware that does it's own handling, via line 218 of the graphql.module.ts file, so it could be an issue of middleware order, but I'm not sure how that could get fixed. Out of curiosity, is there a reason you're relying so heavily on middleware over something like enhancers (guards and interceptors to be specific)? |
@jmcdo29 I'm using middleware to protect every request to |
@manju-reddys why couldn't you make the guard global and have the guard check if a certain metadata is present (something like 'OAUTH_GUARD_SKIP') and if so, skip the guard by short circuiting to a true? |
That's good point but I also wants to inject user and extra security headers upon token verification which will be consumed by downstream, can we do that as well? I haven't given thought about that. |
Absolutely. Objects in JavaScript are passed by reference, meaning if you modify it in one place, you can get the same modification elsewhere. This is how passport initially handles adding |
thank you for the tips, I will give it a try sometime this week and if that works I will drop the middlewares. |
And also how do I inject the user to GrraphQL request? |
You can add it to the request object and get the request object via |
Unfortunately the problem is that, the
|
Do you have the request added to the contrxt as described by the Apollo server docs? For fastify the setting is |
Would you mind pointing me to the right documentation or code reference how I should add |
@jacob87o2 sorry if I wasn't clear, I want to understand how to set the context so the request, reply will be available in the GraphQL context which is missing in |
The link I posted has this snippet, which is essentially what you're looking for: GraphQLModule.forRoot({
context: ({ req }) => ({ req }),
}); Mix that with this API doc and you should have what you need. |
Request related issues have been fixed. |
Bug Report
Upgrade from
7.0.1
to7.4.2
Current behavior
The middleware registered to all requests are not invoked for graphql request and so the user inject into the request is not available to graphql queries.
Input Code
Expected behavior
GraphQL request must first flow through middleware where auth checks will be done and user will be injected for down steam consumption.
Below code works fine in
7.0.1
but doesn't in7.4.2
Possible Solution
Environment
The text was updated successfully, but these errors were encountered: