What type to use for resolver that returns an error when using Nexus
copleykj opened this issue · 1 comments
Question about GraphQL Shield
So this isn't specifically a qraphql-shield question, but I figured I'd take a shot in the dark since it's very likely that someone here uses it with Nexus and might be able to give me a decent answer.
Basically I'm using Nexus and shield together. Shield catches errors by default and so requires returning them. The problem is that I can't find a way to specify an error as the return type for a resolver using Nexus. Is there a proper way to specify this so that TypeScript doesn't complain about the mismatch of the type of the return value and the generated type? Right now I'm just casting the error to any to appease the compiler, but it would be nice to have a proper solution.
Here is a pared down example
mutationField('simpleMutationReturnsError', {
type: nonNull('Error'), // <---- What should go here to specify an error as the return type
async resolve () {
return new ApolloError('This is an error'); // <--- currently casting this using as any
},
});
- I have checked other questions and found none that matches mine.
Hey @copleykj 👋,
Thank you for opening an issue. We will get back to you as soon as we can. Have you seen our Open Collective page? Please consider contributing financially to our project. This will help us involve more contributors and get to issues like yours faster.
https://opencollective.com/graphql-shield
We offer
priority
support for all financial contributors. Don't forget to addpriority
label once you become one! 😄