Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda