I have a mutation where I want to return a boolean value of true but getting this error:
Type 'Promise<boolean>' is not assignable to type 'boolean | PromiseLike<false> | PromiseLike<true>'
Mutation field:
export const Mutation = mutationType({
definition(t) {
t.field('forgotPassword', {
type: 'Boolean',
args: {
email: stringArg(),
},
resolve: async (parent, { email }, ctx) => {
const user = await ctx.prisma.user({ email })
if (!user) {
return true
}
return true
},
})
},
})
full error message:
Type '(parent: {}, { email }: { email: string; }, ctx: Context) => Promise<boolean>' is not assignable to type 'FieldResolver<"Mutation", "forgotPassword">'.
Type 'Promise<boolean>' is not assignable to type 'boolean | PromiseLike<false> | PromiseLike<true>'.
Type 'Promise<boolean>' is not assignable to type 'PromiseLike<true>'.
Types of property 'then' are incompatible.
Type '<TResult1 = boolean, TResult2 = never>(onfulfilled?: ((value: boolean) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = true, TResult2 = never>(onfulfilled?: ((value: true) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<...>'.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Type 'boolean' is not assignable to type 'true'.ts(2322)
definitionBlocks.d.ts(52, 3): The expected type comes from property 'resolve' which is declared here on type 'NexusOutputFieldConfig<"Mutation", "forgotPassword"> & { resolve: FieldResolver<"Mutation", "forgotPassword">; }'
(property) resolve: FieldResolver<"Mutation", "forgotPassword">
Thanks for the report! Fixed in #29
It is a async function and should return promise or observable.
return new Promise((resolve, reject) => {
resolve(true);
})
How did you fix it
Most helpful comment
Thanks for the report! Fixed in #29