mezie
04/11/2018, 10:04 AMUser
and Event
woss
04/11/2018, 11:15 AMattendingUsers
or something like thatmaybeGoing
goingForSure
mezie
04/11/2018, 9:25 PMattendingUsers
from a resolver function?woss
04/12/2018, 9:04 AMcreate
and connect
, create will create a user and connect will connect it with given ID!
...
tags:{
create: {name: "23edsaasdas"}
}
owner: {
connect:{auth0id:"chickens-and-sloths" }
}
...
mezie
04/12/2018, 10:01 AMtype Event {
id: ID! @unique
organizer: User!
title: String!
description: String!
location: String!
date: DateTime!
participants: [User!]!
}
type User {
id: ID! @unique
email: String! @unique
password: String!
name: String!
events: [Event!]!
}
A user can be the organizer of an event and other users can attend the event. With these definitions, how do add a user as a participant to an event from a resolver function?woss
04/12/2018, 10:47 AM[String!]!
is a relation (prisma) and in ‘normal’ graphql is a larray of some stringsmezie
04/12/2018, 12:09 PMconst event = {
async createEvent (
parent,
{ title, description, date, location },
ctx,
info
) {
const userId = getUserId(ctx)
return ctx.db.mutation.createEvent(
{
data: {
title,
description,
date,
location,
organizer: {
connect: { id: userId }
}
}
},
info
)
}
}
woss
04/12/2018, 12:41 PMconst event = {
async createEvent(
parent,
{title, description, date, location, participants},
ctx,
info,
) {
// participants are in format of ["ID", "another-ID", "yeti-another-ID"]
const userId = getUserId(ctx)
return ctx.db.mutation.createEvent(
{
data: {
title,
description,
date,
location,
organizer: {
connect: {id: userId},
},
participants: {
// case you have the IDS
connect: participants.map(id => {
return {id: id}
}),
},
},
},
info,
)
},
}
mezie
04/12/2018, 1:05 PMwoss
04/12/2018, 2:34 PMconnect
them. that means you have the IDs already.participants: {}
and that should create empty arrayupdate
method with connect
mezie
04/14/2018, 4:31 AMString
but I'm getting this error: Field updateEvent of type Event must have a selection of subfieldswoss
04/16/2018, 7:57 AM