apollo server mutation resolver not called
See original GitHub issueThis 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?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@BengBu-YueZhang I’m facing the same issue with my Apollo GraphQL server.
console.log
statements in the mutation resolver are not executed andnull
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!
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:
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 toOr 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!