Skip to content

Get server-generated ID's of inserted rows #13

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

Open
markhalonen opened this issue May 17, 2022 · 6 comments
Open

Get server-generated ID's of inserted rows #13

markhalonen opened this issue May 17, 2022 · 6 comments

Comments

@markhalonen
Copy link

markhalonen commented May 17, 2022

Hey Tim, great looking package here, I especially like the opt-in smart comments design.

I have a query such as

mutation CreateManyPartsTransfers($partsTransfers: [PartsTransferInput!]!) {
    mnCreatePartsTransfer(input: { mnPartsTransfer: $partsTransfers }) {
      clientMutationId
      partsTransfer {
        id
      }
    }
  }

Where I am creating many PartsTransfers rows, and then I would like to get the server-generated ID's back. Currently, it seems to only return 1 id, instead of returning many id's, 1 id for each new row inserted.

Am I missing something or is this just not implemented? And if it's not implemented, how hard do you think it is to implement?

@tjmoses
Copy link
Owner

tjmoses commented May 17, 2022

I personally never implemented this b/c I would of had to build a custom input type to return multiple rows vs. the already written one from an internal postgraphile plugin I borrowed. You can just use a second query to get them that takes place after the mutation. There is a query field you can use on the returned values for this like as show below (just a guess at your table / query name is):

mutation CreateManyPartsTransfers($partsTransfers: [PartsTransferInput!]!) {
    mnCreatePartsTransfer(input: { mnPartsTransfer: $partsTransfers }) {
      clientMutationId
      query {
       allPartsTransfer {
        nodes {
          id
        }
      }
     }
    }
  }

If you want to update the plugin and add the proper type, I would be more than glad to accept a PR. At some point I may update this, just too busy with other stuff. If there was a sponsor I would consider further.

@markhalonen
Copy link
Author

Thanks for the quick response! Unfortunately

query {
       allPartsTransfer {
        nodes {
          id
        }
      }

returns all PartsTransfers, even ones created before this request...

If you want to update the plugin and add the proper type, I would be more than glad to accept a PR. At some point I may update this, just too busy with other stuff. If there was a sponsor I would consider further.

Fully understand. Can you email me [email protected] with an acceptable hourly rate to work on this task? Thanks!

@tjmoses
Copy link
Owner

tjmoses commented May 17, 2022

Right, but as long as the query is within the mutation you'll get the additional created ids then you could then diff the two sets to get the changed ids. Here's another library I created that somewhat automates that. I do need to update this feature though. If that workaround doesn't work, give me a few days and I'll reach out.

@markhalonen
Copy link
Author

Right, but as long as the query is within the mutation you'll get the additional created ids then you could then diff the two sets to get the changed ids

This is large table so getting all the ids is not performant, so this is not a solution

@endurance-chorus
Copy link

@tjmoses Were you able to make progress on this? Or could you point me to where I could make such a change?

@tjmoses
Copy link
Owner

tjmoses commented Feb 12, 2025

@endurance-chorus so mark had some issues with his PR to resolve this, they were laid out here:
#15 (comment)

If you fix those issues on the PR, I'll be more than happy to merge it. Further if you can give a few manual test scenarios you did, to ensure the code will not break that would also be great. I know setting up the testing suite for this plugin, takes significant time so manual tests are fine with me. Also, bump up the package version number a major number (since this could break other packages). Thanks!

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

No branches or pull requests

3 participants