I have the following mutation that I am running: `...
# orm-help
a
I have the following mutation that I am running:
Copy code
async 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:
Copy code
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)
n
Could you share the relevant types from your datamodel? My guess is that you need to implement a type resolver to resolve the relation btween
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-client
a
Copy code
type Person {
  id: ID! @unique
  name: String!
}

type Coop {
  id: ID! @unique
  name: String!
  people: [Person!]!
  chores: [WeeklyChore!]!
}
This is my datamodel
n
You need to implement a resolver for the
people
field like so:
Copy code
const resolvers = {
  // ... Query & Mutation resolvers,
  Coop: {
  	people: (parent) => <http://prisma.coop|prisma.coop>({ id: parent.id }).people()
  }
}
a
@nikolasburk: Is it possible to add another resolver like so?
Copy code
Coop: {
    people: (parent) => <http://prisma.coop|prisma.coop>({ id: parent.id }).people(),
    numberOfPeople: () =>  this.people().then(res => res.people.length)
  }
I mean, I know it is possible..but ahem, I can't find the length of the array that
people
returns
n
You can get the count of a list via the connections API: https://www.prisma.io/docs/prisma-client/basic-data-access/reading-data-TYPESCRIPT-rsc3/#aggregations 🙂
a
Hm..well I can understand getting the count for a type that is a connection, but afaik a list inside an object isn't a connection, or at least it isn't in my case..I think?