Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Correct way of returning Errors from GraphQL resolvers with typescript

I'm trying to return Errors from my resolvers when something is going wrong. An example below. But I'm getting errors from the Typescript compiler.

0]   Types of property 'me' are incompatible.
[0]     Type '(_: {}, __: {}, context: ExtendedContext) => Promise<AuthenticationError | User>' is not assignable to type 'ResolverFn<Maybe<ResolverTypeWrapper<User>>, {}, ExtendedContext, {}> | ResolverWithResolve<Maybe<ResolverTypeWrapper<User>>, {}, ExtendedContext, {}> | undefined'.
[0]       Type '(_: {}, __: {}, context: ExtendedContext) => Promise<AuthenticationError | User>' is not assignable to type 'ResolverFn<Maybe<ResolverTypeWrapper<User>>, {}, ExtendedContext, {}>'.
[0]         Type 'Promise<AuthenticationError | User>' is not assignable to type 'User | Promise<User> | Promise<Maybe<ResolverTypeWrapper<User>>> | null'.
[0]           Type 'Promise<AuthenticationError | User>' is not assignable to type 'Promise<User>'.
[0]             Type 'AuthenticationError | User' is not assignable to type 'User'.
[0]               Type 'AuthenticationError' has no properties in common with type 'User'.

What is the correct way to extend these generated resolver types from graphql-codegen in order to be able return errors that I'm recieving.

export const resolvers: Resolvers<ExtendedContext> = {
  Query: {
    me: async (_, __, context) => {
      if (!tokenIsvalid(context.userData)) {
        return new AuthenticationError("Invalid token"); <---- This is causing errors
      }
      const user = await getRepository(User).findOneOrFail(
        context.userData.userId
      );
      return user;
    },
  },
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!