-
I've setup a basic test subscription that throws inside the async iterator: type Subscription {
test: Date!
} The subscribe function: import timers from 'node:timers/promises';
function resolverTest() {
return (async function* () {
const interval = timers.setInterval(1000);
for await (const _ of interval) {
yield {test: new Date()};
throw new Error('test');
}
})();
} Server setup: import Fastify from 'fastify';
import { createHandler } from 'graphql-sse/lib/use/fastify';
const handler = createHandler({ schema });
const fastify = Fastify();
fastify.all('/graphql/stream', async (req, reply) => {
try {
await handler(req, reply);
} catch (err) {
console.error(err);
reply.code(500).send();
}
});
fastify.listen({ port: 4000 });
console.log('Listening to port 4000'); When I subscribe to It comes from the Would it make sense to forward the error into the classic |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Sorry for the delayed answer. The issue actually stems from I've added a recipe that showcases how you may achieve this by augmenting the |
Beta Was this translation helpful? Give feedback.
-
No need to apology, we are all busy. Instead, thanks a lot for your time and for this amazing library. |
Beta Was this translation helpful? Give feedback.
Sorry for the delayed answer. The issue actually stems from
graphql-js
not handling errors thrown during iteration. I'd prefer having this handled by the user (or graphql-js) instead.I've added a recipe that showcases how you may achieve this by augmenting the
subscribe
function, check it out here.