Hi, guys! I can’t find documentation on how to use...
# prisma-whats-new
a
Hi, guys! I can’t find documentation on how to use “updateOrCreate”. Can you point out an example, please?
n
@alex_ye hey, thanks for the question! We are currently still iterating on how updateOrCreate mutations work, so it's undocumented for now 🙂
a
Oh, I see. Could you please write a simple example of the current usage?
just noticed another thread, let’s move there 🙂
n
nah the other thread is about something similar but not the same 😄
the
update
input argument needs an
id
and at least another argument. if no node is found with that
id
, the
create
input argument is run for the create mutation. For
create
, all required fields need to be specified.
a
updateOrCreateAnswer(update: {id: "123", content: "asd"}, create: {content: "asd"})
is it correct usage?
n
that depends on the required fields of your model
if
content
is the only required field, then yes 🙂
a
it says Answer must have a selection of subfileds
n
Copy code
updateOrCreateAnswer(update: {id: "123", content: "asd"},
 create: {content: "asd"}) {
  id
}
a
Great, now I get it! 🙂 Thanks Nilan!
n
👍