batch updating... do I need the where: {...} part ...
# orm-help
z
batch updating... do I need the where: {...} part if I want to update every row ? (nested update) mutation($chocolateId: ID!) { updateChocolate( where: { id: $chocolateId } data: { sections: { update: { where: {--no filter here, update all--} data: {title:null} }} } ) { id } }
f
Yes, where is required, but you can pass empty object where: {} All records will updated
z
"code": 3040, "message": "You provided an invalid argument for the where selector on ChocolateSection.",
on Prisma... if that matters?
n
you need to use updateMany.
z
but I only want to update single root type (and many nested)... ?
n
ah you're talking about inner updates. No, update accepts a list of objects instead
z
gotcha... mutation($chocolateId: ID!) { updateManyChocolates( where: { id: $chocolateId } data: { sections: { update: { where: {} data: { handles: { update: { where: {} data: { input: { update: { value: null }}}}}}}}} ) { count } }
long tail there... but this is pattern?
n
do all nodes receive the same update?
or are some nodes getting other values than others
z
all nodes are nulled
value:null
n
not sure if that's possible using updateMany off the bat, but you can try 🙂
if it's not possible, you need to do it like in your first version but instead of
update: { where:... }
you need to do
update: [{ where:... }, { where:... }, { where:... },...]
z
no errors but values are unchanged
aha... I'll try the brackets
back to code 3040 error...
' mutation($chocolateId: ID!) { updateChocolate( where: { id: $chocolateId } data: { sections: { update: [{ where: {} data: { handles: { update: { where: {} data: { input: { update: {value: null}} } }}}}]}} ) { id } }'
n
this where can't be {}.
z
but how to update all rows then?
it only allows where: {id: "xxx"}
n
yup that's how you can do it.
z
but it should update all (nested) rows ?
n
you can also query the nodes first, then update them
z
could you please tip me on that syntax?
pretty please, since I don't know how to query then update... just a newbie!
query...update - you mean I could do that without roundtrip?
n
I provided as much input as I can at this point 🙂 If you want to, you can describe your situation in the Forum to find the best approach.
z
indeed - thank you, just I am not sure how to do a query...update in one mutation query, I´ll post to forums yes
n
oh, you can't. I talked about separate queries/mutations.
z
ahh ok, thank you
guess it's time to dig in custom resolvers