mongodb – GraphQL Mutation returns success but it does not update database (Integration of Apollo and Node.js)

I am using Apollo Server with Node.js, The mutation returns a success response but it is not updating database.

Mutation:

type Mutation {
  updateUserName(id: ID!, name: String!): Boolean!
}

Resolver:

Mutation: {
  updateUserName: async (_, { id, name }) => {
    User.updateOne({ _id: id }, { name });
    return true;
  }
}

Expected:

The user’s name field should get updated in MongoDB.

What is happening

The mutation returns true but the name remains unchanged in the database.

What I tried

Environment:

  • Node.js: 18.17.1
  • Apollo Server: 4.7.1
  • Mongoose: 7.3.4
  • MongoDB: 6.0

Question

Is there something about Apollo Server that is preventing the update from executing?

Read more here: Source link