Custom subscription when not using yoga as a server #3273
Closed
santino
started this conversation in
Docs Discussion
Replies: 2 comments
-
Currently, this is what I ended up implementing. export const useSubscription = () => {
return {
async onSubscribe () {
return {
onSubscribeResult: async ({ result, args: { contextValue: { req, reply } } }) => {
req.socket.on('end', () => {
result.return()
reply.hijack()
})
req.socket.on('close', () => {
reply.log.info(
{
res: reply,
responseTime: reply.elapsedTime
},
'request completed'
)
reply.raw.end()
})
for await (const data of result) {
reply.raw.write(
`event: next${EOL}data: ${JSON.stringify(data)}${EOL}${EOL}`
)
}
}
}
}
}
} Let me know if you can think of any improvement |
Beta Was this translation helpful? Give feedback.
0 replies
-
Discard this. I had a faulty setup to deliver an initial subscription value, which led me to think there was an issue with Yoga handling subscriptions. Thanks to @ardatan's comment I ended up digging more and finding the proper way to handle this; as discussed in #3276 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello folks, as mentioned by the title, I am looking to setup subscriptions in my Yoga implementation.
I am not using Yoga as a full server, but instead I am integrating it with my
fastify
instance.The
useGraphQLSSE
plugin only seems to work if Yoga is executed as a server.Do you have any example for writing up a plugin that only handles subscription requests received on my single
/graphql
endpoint?Beta Was this translation helpful? Give feedback.
All reactions