mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.35k stars 237 forks source link

Incorrect overload types of hooks #877

Closed npdev453 closed 2 years ago

npdev453 commented 2 years ago

That code:

 app.graphql.addHook('preExecution', (schema, document, context) => {});

make that error:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '"preExecution"' is not assignable to parameter of type '"onGatewayReplaceSchema"'.ts(2769)
index.d.ts(362, 3): The last overload is declared here.
npdev453 commented 2 years ago

Ah, its because I call it without async keyword. but is it really nessesacy with synchronius logic? (also its conflict with eslint no async without awaits rule)

app.graphql.addHook('preExecution',  async (schema, document, context) => {});

Seems like in type should be something ()=>Promise<T> | T

mcollina commented 2 years ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

It's ok to update the types to ()=>Promise<T> | T.

raulsoledispa commented 2 years ago

@mcollina, I'd like to send a PR to address this issue. Can you assign it to me?

mcollina commented 2 years ago

go for it!