I'm having an error in the return of a Mutation
. Apparently it can not read the id field, but the object I'm sending to GraphQL has this field, and since I'm new to GraphQL I did not understand what the error means.
The error:
{
"errors": [
{
"message": "Cannot return null for non-nullable field UserVoucher.id.",
"locations": [
{
"line": 48,
"column": 5
}
],
"path": [
"createUserVoucher",
"id"
]
}
],
"data": {
"createUserVoucher": null
}
}
The mutation and where I enter the bank (it correctly inserts the element):
createUserVoucher: (parent, args, { user, models }) => {
args['userId'] = user.id;
models.UserVoucher.count({
where: {utilized: true, pinId: args.pinId, userId: args.userId}
}).then( c => {
if (c > 0) {
return []
} else {
models.Voucher.findOne({
where: {
id: args.voucherId
}
}).then( voucher => {
models.UserVoucher.count({
where: { voucherId: args.voucherId }
}).then( c => {
if (c < voucher.captured) {
if (user.name, user.gender, user.username, user.email, user.phoneNumber, user.city, user.state, user.cpf) {
return models.UserVoucher.create(args) //RETORNA AQUI
}
}
})
})
}
});
return []
}
The UserVoucher setting:
type UserVoucher {
id: Int!
nodeId: Int!
userId: ID!
voucherId: ID!
voucher: Voucher
pinId: ID!
capturedAt: DateTime
utilized: Boolean
}
';
The mutation definition:
createUserVoucher(
pinId: Int!,
voucherId: Int!
): UserVoucher
Any idea what I can do to solve this or at least a light to debugar better?