Original resolver executed twice when an error is thrown
mfellner opened this issue · comments
Maximilian Fellner commented
When a resolver throws an error, the original resolver is executed twice.
const resolvers = {
Query: {
hello(parent, args, context) {
console.log("query hello", context.count++);
throw new Error("oops");
},
},
};
const app = Fastify();
app.register(mercurius, {
schema,
resolvers,
context: () => ({ count: 0 }),
graphiql: true,
});
app.register(mercuriusCache, {
ttl: 2, // seconds
all: true,
storage: {
type: "memory",
options: {
size: 2048,
},
},
});
Actual output
query hello 0
query hello 1
Expected output
query hello 0
I was able to debug the code and find the second location where the original resolver gets called:
- first call https://github.com/mercurius-js/cache/blob/v2.0.0/index.js#L184
- second call https://github.com/mercurius-js/cache/blob/v2.0.0/index.js#L257
I've also made a reproduction repository here: https://github.com/mfellner/mercurius-cache-bug
Dependencies:
- fastify: 4.5.3
- mercurius: 10.5.0
- mercurius-cache: 2.0.0
- Node.js: 18.8.0
Matteo Collina commented
This is an interesting bug. Have you got some ideas on how to fix this? I guess we'd need to do quite a bit of refactoring to cater for this case.
@simone-sanfratello wdyt?
Simone Sanfratello commented
Thanks for spotting @mfellner!
I can work on this in the next days, yeah probably some refactor is nice