Arnab
02/04/2019, 10:07 AMasync addPersonToCoop(parent, args, context) {
return await prisma.updateCoop({
data: {
people: {
connect: {id: args.personId}
}
},
where: {id: args.coopId}
})
}
When I do the query directly to prisma, it works:
mutation{
updateCoop(where: {
id: "cjrmnfndf003x0854f33kk8c6"
},
data: {
people: {
connect: {id: "cjrq5m7qa004g0854lgiggn59"}
}
}
){
name
id
people{
id
name
}
}
}
but when I run the mutation that I wrote myself, it says that it can't return null for a non-null field (the people field)nikolasburk
Coop and people. You can find some info here: https://www.prisma.io/tutorials/a-guide-to-common-resolver-patterns-ct08/#scenario:-implementing-relations-with-prisma-clientArnab
02/04/2019, 10:14 AMtype Person {
id: ID! @unique
name: String!
}
type Coop {
id: ID! @unique
name: String!
people: [Person!]!
chores: [WeeklyChore!]!
}Arnab
02/04/2019, 10:14 AMnikolasburk
people field like so:
const resolvers = {
// ... Query & Mutation resolvers,
Coop: {
people: (parent) => <http://prisma.coop|prisma.coop>({ id: parent.id }).people()
}
}Arnab
02/04/2019, 10:57 AMCoop: {
people: (parent) => <http://prisma.coop|prisma.coop>({ id: parent.id }).people(),
numberOfPeople: () => this.people().then(res => res.people.length)
}Arnab
02/04/2019, 10:57 AMpeople returnsnikolasburk
Arnab
02/04/2019, 11:19 AM