-
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
Not able to access response object from context in apollo-server-fastify #3156
Comments
Yeah, the same issue but you can pass File const fp = require('fastify-plugin');
const {ApolloServer} = require('apollo-server-fastify');
// **** Plugin: plugins/fastify-apollo-server/index.js
module.exports = fp(async ( fastify, opts, next ) => {
const server = new ApolloServer({
/* ... */
context: async request => {
const {reply} = request;
return {
request,
reply, // res: reply,
app: fastify,
};
},
});
fastify.addHook('preHandler', async ( request, reply ) => {
if ( String(request.req.url).startsWith('/graphql') ) {
request.reply = reply;
}
});
fastify.register(server.createHandler());
next();
}, {
name: 'fastify-apollo-server',
}); File: const app = require('fastify')();
// Plugins
app.register(require('plugins/fastify-apollo-server'));
(async function () {
await app.listen(3000);
})(); |
@blacksmoke26 seems like kind of hack, but thats simplest solution as well. |
Seems at least somewhat related to #2476. |
@abernix unfortunately, they're unrelated. If you look at the The linked issue is about |
I've been having the same issue and was able to track down the cause. Should have a bug-fix PR up shortly, I'll be sure to link this issue. Meanwhile, if you'd like to check out the fix here it is -> autotelic#1 |
Any update on this one? |
#3895 is awaiting review. In the meantime I've published a standalone version of apollo-server-fastify with the fix applied, here: https://github.com/autotelic/apollo-server-fastify. |
Waiting on #3895 to be merged. Planning to use it to set (JWT) authentication cookies. |
Would be great to see this merged! 🙂 |
Previously I was using
apollo-server-express
and I wanted to migrate to fastify so I change it toapollo-server-fastify
. But it started giving lots of issues.One of such issue is - Not able to access
res
object from context function.Below code was working perfectly but res object itself was not available with
apollo-server-fastify
The text was updated successfully, but these errors were encountered: