Hi all, can anyone explain how a list upsert opera...
# orm-help
w
Hi all, can anyone explain how a list upsert operation works? I want to update a list of
ChecklistItem
that’s part of another another model. The input has this form:
Copy code
input ChecklistItemUpsertWithWhereUniqueWithoutRequestInput {
  where: ChecklistItemWhereUniqueInput!
  update: ChecklistItemUpdateWithoutRequestDataInput!
  create: ChecklistItemCreateWithoutRequestInput!
}
What data do I need to provide for the upserts to be successful? I don’t understand why the
where
field is needed in the case of a “create” upsert
h
where
is used to determine if it should create new record or update already created one
w
thanks, if it should create a new record, should I provide where: { id:
null
or
undefined
}?
h
Then what is point of upsert? You can provide for example
id
and if you don't provide it you create new one. So you can pass there null or undefined but its extra work
w
I have a list of mixed existing and new items, so to create/update in a single mutation I need to upsert them
so sometimes they have an
id
sometimes they don’t
so I’ve tried with both
null
and
undefined
but I’m getting the error
You provided an invalid argument for the where selector on ChecklistItem.
h
What is your model and your mutation
you need to do something like
where: { id: itemId }
w
Copy code
type ChecklistItem {
  checked: Boolean!
  code: ACTIVITY_CODE!
  createdAt: DateTime!
  id: ID! @unique
  request: Request @relation(name: "RequestChecklist")
  subcode: CHECKLIST_CODE!
  updatedAt: DateTime!
}

type Request {
  budget: Int
  checklist: [ChecklistItem!]! @relation(name: "RequestChecklist")
  createdAt: DateTime!
  description: String!
  id: ID! @unique
}
something like this
I’m updating a
request
h
Nested upsert don't work at all btw 🙂
w
so I need to do it in the
updateRequest
resolver?
and upsert manually
h
yea if i am not mistaken
w
thanks 🙂