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

197
Vistas
GraphQL resolve GraphQLObjectType

I'm using express-graphql along with the following query:

invitations {
    sent 
    received
}

The schema definition (simplified) is as follows:

const InvitationType = new GraphQLObjectType({
    name: 'InvitationType',
    description: 'Friends invitations',
    fields: {
        sent: {
            type: new GraphQLList(GraphQLString),
            description: 'Invitations sent to friends.',
            resolve() {
             return ['sentA'];
            }
        },
        received: {
            type: new GraphQLList(GraphQLString),
            description: 'Invitations received from friends.',
            resolve() {
             return ['receivedA', 'receivedB'];
            }
        }
    }
});

// Root schema
const schema = new GraphQLSchema({
    query: new GraphQLObjectType({
      name: 'RootQueryType',
      fields: {
          invitations: {
              type: InvitationType // no resolve() method here.
          }
      }
    })
});

However the resolve methods are never called for sent and received fields. The query above returns:

{data: {invitations: {sent: null, received: null}}}

Is there any way to resolve the nested fields (sent and received) without defining a resolve() method on parent (invitations) field?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This worked for me! According to GraphQL Documentation, The execution will continue if the resolve method returns a non-scalar. So the following code works:

// Root schema
const schema = new GraphQLSchema({
    query: new GraphQLObjectType({
      name: 'RootQueryType',
      fields: {
        invitations: {
          type: InvitationType,
          resolve: () => ({}) // Resolve returns an object.
        }
      }
    })
});

Hope this helps. Cheers!

about 4 years ago · Santiago Trujillo 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