-
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
apollo-server-express
: allow customization of how response is sent (eg, allow you to call next
afterwards)
#5560
Comments
I believe the standard way of doing logging in Express is to use the |
(I don't believe this changed in AS3, but if you can share a pair of reproductions showing how it changed (eg codesandbox.io or repos I can clone) I'd be happy to at least update the migration guide.) |
Hi thanks for your reply! Firstly, apologies; I went back to my v2 project and the middlewares I thought were being called after AS are not relevant (and checking the AS code confirms this wouldn't have worked in v2 anyhow). I checked the express v4 documentation and can't find any mention of I understand and confirmed for myself from the express documentation that there's no clear right or wrong in expecting However as you mentioned in #3833:
would this be something you would still consider adding? It'd mean that the change is opt-in for anyone who wants/needs it and can be done as a minor version bump for AS3 that wouldn't disrupt or break any current implementations as I can understand why you might not want to just throw 3 |
I have gone ahead and implemented the I can see the 'finished' request log occurring before other middlewares have done their logging though which indicates this hasn't helped solve the issue. |
How do the other middlewares do their logging? Do they also use finish? It just seems strange that we would make our "handle a request and send a full response" middleware work differently from core Express middleware. |
I took a look at
I understand what you mean there, but I don't see it doing any harm to AS by adding opt-in support for this given how small of a change it is and because I'm not the first to request/find this sort of thing (#3833). I think a little more context about what I'm using AS with would help - our express server uses routing-controllers has |
What happens when you combine |
Hey @glasser, I really appreciate you taking the time to reply to me each time and answer my questions. However, this is really is starting to feel like we're making a mountain out of a mole hill here. This is (in my view) a really simple and reasonable request that has come up before (#3833) and I can't understand why Apollo would be reluctant to add an Please understand and empathize with me here a bit - I'm not trying to be rude, difficult or unreasonable, I just have a problem and a tech stack that we've already invested in and we want to use Apollo's solution for this part of it.
I wouldn't expect to mount I still believe your original suggestion for an Thanks |
Hmm. I really think boolean But what about something a bit more flexible instead. Right now we have this weird Connect-compatibility code:
What if we combined this concern with cleaning up the compatibility code, and had an option to
but connect users could call Would that solve your issue? (I'm passing in the whole httpQueryResponse with headers and status code just in case it's helpful to look at it for context but I think it's reasonable to not require you to copy headers and status code to |
apollo-server-express
does not call next()
which stops express middlewares from runningapollo-server-express
: allow customization of how response is sent (eg, allow you to call next
afterwards)
Reopening and renaming this because I think it would be a helpful hook; I don't think it makes sense for the core team's roadmap but we are happy to review a PR implementing something like my suggestion above. |
I still think that "working kind of like how But Apollo Server 4 makes building your own web framework integration easy. The entire Express integration is barely a hundred lines of code including imports and comments. If you'd like to build your own Express integration that calls |
Hi there,
Have been upgrading my stack to v3 and have noticed that express middlewares placed after the graphql server middleware are not run. I'm reasonably sure this was working in my v2 project beforehand.
My use case is that I have a logger that reports when a request is complete and it is not called after a request to the
/graphql
endpoint but is correctly called after requests to other endpoints on the express server.I believe the fix is simple, there are 3 places where
next()
just needs to be called so express can continue running middlewares.I made a copy of
ApolloServer.ts
in my project and added thenext()
calls onreturn next();
return next(error);
After making these changes, I can see my post-request logger working again on the
/graphql
endpoint.Hopefully this is clear enough, apologies that I do not have time to create a reproduction repo to show the issue.
The text was updated successfully, but these errors were encountered: