-
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
Supporting subsequent middleware #3833
Comments
Hey there, I have a different setup than yours, but could you please try using compose-middleware and see if it solves the problem. If true, then that would be your temporary fix and it would be solved by this proposal. |
Unfortunately, this does not solve my problem. But I don't see how using |
I have/had a very different error than yours and stumbled on your issue: I had trouble setting up an authentication middleware on Apollo Server with Express, but with a completely different setup and deployment problems. I went over the proposal before and noticed:
And further below it:
These are the only reasons why I thought it might work for you. I would advise you go over the proposal, it might help you. Besides that, I think your are right in thinking that the error comes from the Apollo Midlleware. |
This goes back to #462. I understand how not calling As a way to provide you more concrete suggestions and hopefully unblock your use-case: can you provide the use-case for what it is you need this middleware to do after Apollo has handled the GraphQL bits? Is it something that could be accomplished with the Plugin API? |
I already tried using the Plugin API, unfortunately my use case was not supported with it. I am using Oracle as DB, and I want to manage the database connections from the node-oracledb package on a per-request-basis. This means that a connection should be opened at the beginning of an incoming request and closed after the request was handled. My first idea was to use the context object. My context initialization function opened a database connection and added it to the context object, and every resolver function could use the database connection from the context object. As I realized that I can not use express middlewares to close the database connection (because they do not get called), I found the Plugin API. It seemed working fine at the beginning, but after a while I noticed that my server did not close every connection. I found out that the context object initialization function gets called everytime a request was made to the server, but the Plugin API functions only get called when a request to the /grahql endpoint was made. Because of this, every time a request is made to an other endpoint than /graphql, a connection gets opened but not closed. I then tried opening the database connection in the I have now switched to use a custom express server with the official express-graphql middleware, because this seems like the only setup wich supports my requirements. If you have any suggestions on how to implement my use case with |
i think the following code should be able to function as you need.
However, i am still curious about your way of solving it using another grapqhl server. |
I think @yueyueniao90's suggestion is the appropriate one. When This is analogous to how, say, Are there use cases that really can't be solved with |
Hey there. I have met the same problem as @mariushab did. The problem is, using I dont really know why serve static middleware works this way, but I am not sure apollo middleware has to follow it. My case was using Sentry. Setting it up, I have found that I cant use it correctly due to apollo problem. Here is the guide (watch Express section): As you can see, firstly, we have to use requestHandler, then controllers (aka apollo middleware) and errorHandler. But the problem is when something is wrong, apollo does not allow sentry to be flushed in errorHandler, due to next is not called. |
@wolframdeus This issue is a duplicate of #5560. The last comment on that is a solution I proposed. I'd be happy to take a look at a PR for it; I've reopened that issue with some more details. |
I am actually not sure if this is a bug or a feature request.
Consider the example below:
Unfortunately, the third middleware never gets called. This means that every middleware behind the apollo middleware never gets called, which I don't think is a useful behaviour.
I looked around in the source code, and it seemed to me that adding a
next();
at line 53 insrc/expressApollo.ts
would solve the problem.However, I don't know about the implications this change would bring and if there's a reason why currently the next middleware's don't get called. That's why I opened this issue to get some comments on the idea, and if there are any consequences on implementing this.
If there are no objections, I would happily open a pull request to fix this bug/implement the feature.
The text was updated successfully, but these errors were encountered: