Jim
06/29/2018, 8:26 AMreturn ctx.db.mutation.updateUser(
{
where: { id },
data: {
name,
email,
body,
},
},
info,
);
Is there a smart way to make the name, email and body optional, and only update them if a value has been passed?
I could do it with some if statements but it makes my soul feel dirty:
if (name) {
ctx.db.mutation.updateUser(
{
where: { id },
data: {
name,
},
},
info,
);
}
if (email) {
ctx.db.mutation.updateUser(
{
where: { id },
data: {
email,
},
},
info,
);
}
if (body) {
ctx.db.mutation.updateUser(
{
where: { id },
data: {
email,
},
},
info,
);
}
Jenkins
06/29/2018, 8:54 AMconst f = (root, { id, ...rest }, { db }, info) =>
db.mutation.updateUser({
where: {
id
},
data: {
...rest
}
}, info);
Jenkins
06/29/2018, 8:55 AMtype Mutation {
f(
id: ID!
name: String
email: String
body: String
): User
}