Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multiple items in single mutation #326

Open
tomsimpkins opened this issue Feb 14, 2022 · 9 comments
Open

Update multiple items in single mutation #326

tomsimpkins opened this issue Feb 14, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@tomsimpkins
Copy link

What would you like to be added:
Update of multiple items via a single mutation:

mutation {
  plans(update: $data) {
    id
    name
  }
}

where data is:

[{ id: 10, name: "plan1" }, { id: 11, name: "plan2" }]

Why is this needed:
I don't believe this is possible currently without implementing a custom mutation, and I think this abstraction is generically helpful.

The documentation suggests that this is possible with upsert:
https://github.com/dosco/graphjin/wiki/Guide-to-GraphQL#bulk-upsert

However, I haven't got this to work successfully via the packaged Graphjin UI - the error message coming back is complaining there is a missing where clause, implying the primary key is not matched if this behaviour is indeed intended.

I'm very aware this might be my misunderstanding, so apologies in advance if that is the case

@tomsimpkins tomsimpkins added the enhancement New feature or request label Feb 14, 2022
@MIRO1990
Copy link

I have the same issue too, I am getting an error when trying to update more than one item at once

@dosco
Copy link
Owner

dosco commented Feb 15, 2022

This is not supported as yet but we could definitely add it

@ClassicSours
Copy link

Working on a feature now using y'alls platform and bulk upserts would be amazing to have. If i have a large array of rows being able to update/insert rows in our table that is unique by an unchanging column in a single connection as opposed to opening a connection for each one would be a real game changer.

@jquintozamora
Copy link

I'm having the same issue, is there any ETA in place for solving this? thanks!

@ClassicSours
Copy link

ClassicSours commented Apr 1, 2022

I'm having the same issue, is there any ETA in place for solving this? thanks!

this may not be the solution you are looking for but how i was able to side step this issue was moving from the trigger updating my audit table to going the other way

instead of inserting to my mutable table with a bulk upsert and having a trigger update the "immutable" audit table we instead only bulk insert into the audit table and have a trigger on insert into the audit table that per row updates/inserts into our mutable table we actually care about upserting on

hope this helps/save yall some time.

@MIRO1990
Copy link

MIRO1990 commented Apr 4, 2022

@ClassicSours as I understood from your answer, you are using upsert to either update if the row exists of insert if it doesn't.
if that's the solution you are suggesting, then unfortunately that won't quite work as expected, because the validation on insert is different from the validation on update.
For example, if you are inserting a new row, then you would want to have some required columns to complete creating a new row, but with the update case, you don't need all the required columns to update the row, you would only need one column to be updated for example, in that case, the upsert would fail and ask to include all the columns values for update in order to match the validation on insert , so it's not ideal in that case.
please let me know if I misunderstood your idea.
Thank you :-)

@ClassicSours
Copy link

@ClassicSours as I understood from your answer, you are using upsert to either update if the row exists of insert if it doesn't. if that's the solution you are suggesting, then unfortunately that won't quite work as expected, because the validation on insert is different from the validation on update. For example, if you are inserting a new row, then you would want to have some required columns to complete creating a new row, but with the update case, you don't need all the required columns to update the row, you would only need one column to be updated for example, in that case, the upsert would fail and ask to include all the columns values for update in order to match the validation on insert , so it's not ideal in that case. please let me know if I misunderstood your idea. Thank you :-)

that is essentially correct, we have a couple of columns we want the database to have ownership over, however the rest should be user input with a unique primary key that defines each row. Ideally upsert would either insert a new row, or update an existing row with matching primary key. Being able to define some "on conflict" logic for the update case would likely be needed as well as that is what the trigger we have made is essentially doing.

@MIRO1990
Copy link

MIRO1990 commented Apr 4, 2022

@ClassicSours
Right got it, as I understood, you have implemented a way for the trigger to resolve any conflicts between update and insert by accessing the database by the primary id.
Thanks for explaining.

@MIRO1990
Copy link

MIRO1990 commented Apr 5, 2022

@ClassicSours seems like GraphJin doesn't allow upsert mutation on a VIEW because VIEW doesn't have primary key or unique id that Graphjin requires.
Do you know any possible solution for this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants