Trying to figure out how to create a item if it do...
# orm-help
j
Trying to figure out how to create a item if it doesn't exist or update it if it does...
j
What is the purpose of the update and create?
n
either you want to update or you want to create, hence two objects
for create you need at least all required fields, for update you need at least any field. those are different requirements.
j
So there is no way create if it doesn't exist, update if it does. It requires both update and create. I plan to run a lambda script every two hours to fetch data and update / create.
n
well, that is EXACTLY the way to create if it doesn't exist, update if it does.
You just need to specify both all the time.
l
Oh sorry, I didn't understand your question and messed it up. That's why we have Nilan 🙂
j
So in my case I have boat loads of fields. (real estate). So I would need to copy it for create and upsert?
n
Yes. But both are objects, so it's still two GraphQL/(presumably) JavaScript variables.
If this somehow doesn't fit your use case, you can always split it up in an
exists
query +
create
OR
update
mutation by hand.
j
So where means find whatever your looking for, if it doesn't exist create, if it does it updates and create doesn't get executed.
n
where
accepts any unique field. And yep, it's as you say.
j
I may just skip the mutation part in general, waiting on the monogdb connector cause i already seed my database directly through mongo. I have a lambda function that runs every two hours that I update directly through mongo. I don't plan to use a SQL database when I push this live. So I was just experimenting the mutation side because i done forgot the SQL. lol
So is nested mutations not working correctly with upsert?
n
That's correct.
j
Oh ok.
n
That's discussed in the issue @lawjolla shared at the very top of this thread.
j
Yeah I am mind blank today.
So i could run a check to see if something exist, then use create if it doesn't, use update if it does...