Mike Bowen
02/13/2019, 8:25 PMjs
type Club {
id: ID! @unique
createdAt: DateTime!
name: String!
description: String!
members: [User!]!
}
type User {
id: ID! @unique
firstName: String!
lastName: String!
email: String! @unique
clubs: [Club!]!
password: String!
}
where there's a relationship between Users and Clubs (Clubs can have many members
(Users) and Users can belong to many clubs
) I'd like to make a mutation that adds an existing User
to an existing Club
. This is what I have, and it's not working:
js
async function addUserToClub(parent, args, context, info) {
console.log('connecting user with id: ' + args.id);
console.log('to: ' + args.clubid);
const user = context.prisma.updateUser({
data: {
clubs: {
connect: [
{
id: args.clubid
}
]
}
},
where: {
id: args.id
}
})
return user;
}
Mike Bowen
02/13/2019, 8:26 PMclubs
... clubs is null
)Mike Bowen
02/13/2019, 8:27 PMMike Bowen
02/13/2019, 8:27 PMMike Bowen
02/13/2019, 8:29 PMclubs: {
connect:
{
id: args.clubid
}
}
with no luck either