ezeikel
03/18/2019, 10:57 PMfollow and following fields in ONE Mutation after one User follows another rather than having to fire off a separate Mutation for each User to update the respective fields like how it is done here https://github.com/prisma/prisma/issues/1609#issuecomment-365266599
async follow(parent, { username }, ctx, info) {
const auth0Id = await parseUserAuth0Id(ctx)
await ctx.db.mutation.updateUser({
where: { auth0Id },
data: {
following: {
connect: [{ username }]
}
}
})
return await ctx.db.mutation.updateUser({
where: { username },
data: {
followers: {
connect: [{ auth0Id }]
}
}
}, info)
},
async unfollow(parent, { username }, ctx, info) {
const auth0Id = await parseUserAuth0Id(ctx)
await ctx.db.mutation.updateUser({
where: { auth0Id },
data: {
following: {
disconnect: [{ username }]
}
}
})
return await ctx.db.mutation.updateUser({
where: { username },
data: {
followers: {
disconnect: [{ auth0Id }]
}
}
}, info)
},