I'm using GraphQL with Sequelize and I have a mutation that returns null.
I have tried changing the resolver for the mutation about in a different few ways, but it always returns null when I test it with GraphiQL.
Heres the resolver written in a few different ways:
1 - Initially i had the idea to add wrap the functionality in a promise.
resolve(root, args) {
return new Promise((resolve, reject) => {
db.record.findOne({ where: { UID: args.UID } })
.then(record => {
let newArr = undefined
if (record.watched == null) {
newArr = [args.value]
} else {
let old = record.watched
newArr = old.concat([args.value])
}
db.record.update({ watched: newArr }, { where: { UID: args.UID } })
.then(record => {
resolve(record)
})
})
})
}
2 - Here, I return a promise.
resolve(root, args) {
db.record.findOne({ where: { UID: args.UID } })
.then(record => {
let newArr = undefined
if (record.watched == null) {
newArr = [args.value]
} else {
let old = record.watched
newArr = old.concat([args.value])
}
return db.record.update({ watched: newArr }, { where: { UID: args.UID } })
})
}
3 - Below I just returned the record directly.
resolve(root, args) {
db.record.findOne({ where: { UID: args.UID } })
.then(record => {
let newArr = undefined
if (record.watched == null) {
newArr = [args.value]
} else {
let old = record.watched
newArr = old.concat([args.value])
}
db.record.update({ watched: newArr }, { where: { UID: args.UID } })
.then(record => {
return record
})
})
}