question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

field resolver is not being called

See original GitHub issue

Hello,

Could you please help me to find where can I find an answer or documentation describing this situation?

I know I can easily do this if I use javascript for building the scheme, but the syntax needs much more words 😄

Here is the code of schema and resolver:

const { buildSchema } = require('graphql');

const schema = buildSchema(/* GraphQL */ `
  type Position {
    x: String
    y: String
  }

  type Location {
    name: String!
    position: Position
  }

  type Query {
    locations: [Location!]!
  }
`);

const root = {
  Location: {
    position() {
      // this line is not called <-------------------
      return new Promise(resolve => {
        setTimeout(() => {
          resolve({ x: 111, y: 222 });
        }, 300);
      });
    },
  },
  locations() {
    return [{ name: 'test' }];
  },
};

module.exports = {
  schema,
  root,
};

Here is the query

{
  locations {
    name
    position {
      x
      y
    }
  }
}

here is the result:

{
  "data": {
    "locations": [
      {
        "name": "test",
        "position": null
      }
    ]
  }
}

Versions:

    "express": "^4.14.1",
    "express-graphql": "^0.6.6",
    "graphql": "^0.10.1",

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
sai-frogocommented, Sep 12, 2018

@IvanGoncharov @asci Can you post the root variable here. I still couldn’t understand

1reaction
IvanGoncharovcommented, May 23, 2018

@vivex In @asci example you should change Location => 'locations` here:

const root = {
  Location: {
    position() {

Details here: http://graphql.org/graphql-js/object-types/

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL field's resolver not getting called - Stack Overflow
I set up my resolvers based on Apollo's GitHunt-API example, but the resolver on the field "review.extraStuff" never gets called.
Read more >
Resolvers - Apollo GraphQL Docs
We want to define resolvers for the numberSix and numberSeven fields of the root Query type so that they always return 6 and...
Read more >
Resolvers | NestJS - A progressive Node.js framework
Resolvers. Resolvers provide the instructions for turning a GraphQL operation (a query, mutation, or subscription) into data. They return the same shape of ......
Read more >
Execution - GraphQL
When a field is executed, the corresponding resolver is called to produce the next value. If a field produces a scalar value like...
Read more >
Resolvers – GraphQL Tools
It's just every resolver function being called in a nested way according to the layout of the query. Default Resolver. You don't need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found