Nexus: Type 'Promise<boolean>' is not assignable to type 'boolean | PromiseLike<false> | PromiseLike<true>'

Created on 11 Feb 2019  路  3Comments  路  Source: graphql-nexus/nexus

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">
typbug

Most helpful comment

Thanks for the report! Fixed in #29

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bizmedia picture bizmedia  路  4Comments

StevenLangbroek picture StevenLangbroek  路  6Comments

capaj picture capaj  路  5Comments

hatchli picture hatchli  路  5Comments

huv1k picture huv1k  路  6Comments