Postgraphile: Mutations for creating lists of objects/rows in one request?

Created on 30 Aug 2018  Â·  4Comments  Â·  Source: graphile/postgraphile

I'm submitting a ...

  • [x] feature request

Would it be possible to create mutations which accept an array of objects to be created?

  • (E.g. adding an array of todos to a list instead of one at a time / setting up multiple relationships in one go, etc.) I.e. Submitting [InputOne, InputTwo, InputThree, etc.] to one mutation.
  • The utility being:

    • One request on the client

    • Easier to know when to refresh the ui when creating multiple objects at the same time

Current behavior:

  • Multiple calls to createSomeObject
  • input: CreateSomeObjectInput!
  • payload: SomeObject

Expected behavior:

  • One call to createSomeObjects / createMultipleSomeObject?
  • input: [CreateSomeObjectInput!]
  • payload: SomeObjectConnection / similar

Just a thought, looking forward to what yout think,

Many Thanks

✨ Possible via v4 plugin ✨ feature 📄 add-to-docs

Most helpful comment

I am currently facing the same problematic to deal with lists of data to insert/update/delete.

From what I've read there are 3 available options :

  • stored functions : that would require a function everytime we need a plural mutation.
  • custom postgraphile plugin : I'm not familiar with writing custom plugins but this looks like the cleanest way.
  • query batching : just call n times the singular query on the client side and let query batching concat them in one.

To the developers who faced this problem in the past : how did you deal with this ?

All 4 comments

Yeah, that should be possible with a plugin. You might be able to take the existing mutation plugins, do a few naming and plurality tweaks, and have it work.

Another approach is to create a SQL function to do it, a bit like this: https://gist.github.com/benjie/9793993f9dafc2dcf239960a41c7eda8

[semi-automated message] To keep things manageable I'm going to close this issue as I think it's solved; but if not or you require further help please re-open it.

I am currently facing the same problematic to deal with lists of data to insert/update/delete.

From what I've read there are 3 available options :

  • stored functions : that would require a function everytime we need a plural mutation.
  • custom postgraphile plugin : I'm not familiar with writing custom plugins but this looks like the cleanest way.
  • query batching : just call n times the singular query on the client side and let query batching concat them in one.

To the developers who faced this problem in the past : how did you deal with this ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssomnoremac picture ssomnoremac  Â·  5Comments

tonyhschu picture tonyhschu  Â·  3Comments

Venryx picture Venryx  Â·  4Comments

tazsingh picture tazsingh  Â·  3Comments

jwdotjs picture jwdotjs  Â·  5Comments