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

195
Views
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 answers
Answer question

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 Report
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!