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.

apollo server mutation resolver not called

See original GitHub issue

This is my schema


const typeDefs = gql`
  type Query {
    users(pagestart: Int = 1, pagesize: Int = 10): UsersResponse
    user(id: ID!): User!
    me: User
  }

  type Mutation {
    addUser(user: UserRequest): UserResponse
    updateUser(user: UserRequest): UserResponse
    login(user: UserRequest): UserResponse
    logout: UserResponse
  }

This is my resolvers


module.exports = {
  Query: {
    // ...
  },
  Mutation: {
    addUser (_, { user }, { dataSources }) {
      return dataSources.UserDatasource.addUser(user)
    }
  }
}

When I sent a mutation, the resolvers mutation was not invoked. I added consoon.log in resolvers Mutation, which did not print on the console. Resolvers’ Query is all right. Any good Suggestions?

image

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
dakshshah96commented, Mar 3, 2020

@BengBu-YueZhang I’m facing the same issue with my Apollo GraphQL server. console.log statements in the mutation resolver are not executed and null is always returned. The mutation, however, shows up correctly in the GraphQL Playground schema but never gets executed.

Would love to know how you were able to solve this!

0reactions
BenjaminDavidMoorecommented, Apr 8, 2022

Probably a little late for the previous posters, but to help any future soles coming here in a time of desperation, I had the same issue (resolver always returning null and no logs being executed in the resolver) when using Apollo Server with Typescript. The issue for me was that I was importing my resolvers with a glob like so:

const resolversArray = loadFilesSync(path.join(__dirname, './**/*.resolvers.ts'));

Which when transpiled by Typescript, doesn’t change the glob pattern… note the .ts which means when you look at your transpiled version, it’s still looking for resolver files with the .ts extension. I recommend you either change your glob to

const resolversArray = loadFilesSync(path.join(__dirname, './**/*.resolvers.{ts,js}'));

Or manually / explicitly combine your resolvers yourself. Either way, I hope this helps, and if not, try looking to make sure you’ve properly brought in all of your resolvers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers - Apollo GraphQL Docs
To accomplish this, it uses resolvers. A resolver is a function that's responsible for populating the data for a single field in your...
Read more >
Apollo GraphQL: Resolver not called on mutation subfield
I don't understand why the hello resolver is not called and the query field is null . The status field is duly filled...
Read more >
Creating a GraphQL Server with Apollo
Define a resolver function for a mutation. To define resolvers for mutations we need to introduce a Mutation property on our exported object,...
Read more >
Resolvers – GraphQL Tools
If you're not familiar with promises, here's a brief overview. ... The collection of resolvers is called the "resolver map".
Read more >
Execution - GraphQL
After being validated, a GraphQL query is executed by a GraphQL server ... When a field is executed, the corresponding resolver is called...
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