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

302
Vistas
Why GraphQL child resolvers do not receive the obj/parent argument?

I wrote some resolvers following the default GraphQL resolver function' signature that can optionally accept four positional arguments: fieldName: (parent, args, context, info) => data;. But the parent argument is completely absent in child resolvers:

...
const resolvers = [
    {
        Query: {
            prop1: (parent, args, context, info) => ({
                childProp1: (args, context, info) => 'Child Property 1',
                childProp2: (args, context, info) => 'Child Property 2',
            }),
        }
    }
]

const server = new ApolloServer(
    {
        typeDefs,
        resolvers,
    }
);

Unfortunately, I did not find any reference about child resolvers function' arguments in the GraphQL documentation. So I wonder how would be the right way to get the parent object in child resolvers.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Resolvers that are methods of the object whose fields are accessed do not need a parent argument, they are called as methods with their this argument pointing to the object.

When you have

class Value {
    constructor(x) {
        this.property = x;
    }
    methodChild() {
        return this.property;
    }
}
const resolvers = {
    Query: {
        prop1: (parent, args, context, info) => new Value('Child Property X'),
    },
    Value: {
        resolverChild: (parent, args, context, info) => parent.property;
    }
}

then you can declare a

type Value {
    property: String; # directly accessed as value property
    methodChild: String; # directly invoked as method
    resolverChild: String; # separately resolved
}

and all three fields will result in the same value.

about 4 years ago · Juan Pablo Isaza Denunciar
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