I am trying to execute a mutation taking an input type object as parameter but the parameter is not passed to the resolver
Below are my typeDefs.ts and resolver.ts files:
typeDefs.ts
type Mutation {
registerUser(input: UserRegistrationInput): AuthPayload
}
input UserRegistrationInput {
email: String
password: String
}
type AuthPayload {
token: String
message: String
}
resolver.ts
Mutation: {
registerUser: (_, args) => {
console.log(args)
}
}
When I execute this mutation in the GraphQL playground with the query variables, console.log() echo an empty object {}
Mutation
// Mutation
mutation RegisterUser($input: UserRegistrationInput) {
registerUser(input: $input) {
message
token
}
}
// Query variables
{
"input": {
"email": "john.doe@example.com",
"password": "123456"
}
}
However if the mutation takes different parameters instead of an input type, it works. console.log() echo the object { "email": "john.doe@example.com", "password": "123456" }
typeDefs.ts
type Mutation {
registerUser(email: String, password: String): AuthPayload
}
Mutation
// Mutation
mutation RegisterUser($email: String, $password: String) {
registerUser(email: $email, password: $password) {
message
token
}
}
// Query variables
{
"email": "john.doe@example.com",
"password": "123456"
}
I can't figure out why in case of input type the arguments are not passed to the resolver.