Update request for an array field in the model


#1

Hello! There’s a model.

 type User {
  id: ID! @unique @id # read-only (managed by service)
  auth0id: String @unique
  email: [String!] @unique @scalarList(strategy: RELATION)
  stripe_customer_id: String
  name: String!
  guest: Boolean
  createdAt: DateTime! @createdAt # read-only (managed by service)
  updatedAt: DateTime! @updatedAt # read-only (managed by service)
  facebookUserId: String @unique
  roles: [Role] @scalarList(strategy: RELATION)
  #relationships
  worksAt: Producer @relation(name: "UserAtProducer")
}

I am currently using the update request:

gql`
mutation updateUserWithNewProducer($id: ID, $data: ProducerCreateWithoutUsersThatWorkHereInput){
  updateUser(
    data: {
      worksAt: {
        create: $data
      }
    }
  where: {id: $id })
  {
    name, id
  }
}`

But in our project we don’t want to pass the id during mutations anymore. The unique identifier we get from the Auth0 service on the server, so we don’t need to pass anything using ‘where’. But prisma forces us to use ‘where’ when updating and deleting requests. So we decided to use email for ‘where’. But the problem is that the email field in the model is an array and this is due to the architecture of the application.

Can we use a request like this without changing the model?

gql`
mutation updateUserWithNewProducer($email: [String!], $data: ProducerCreateWithoutUsersThatWorkHereInput){
  updateUser(
    data: {
      worksAt: {
        create: $data
      }
    }
  where: { email: $email })
  {
    name, id
  }
}`

I’ve been looking at the documentation - https://github.com/prisma/prisma/blob/master/docs/1.14/04-Reference/03-Prisma-API/04-Mutations.md. But I have not found an answer to my question.