https://kotlinlang.org logo
Title
r

rocketraman

05/10/2021, 3:58 PM
Is there a way to send multiple mutations in one request? I'm not seeing any way to specify a list of mutations in the client API.
m

mbonnin

05/10/2021, 4:00 PM
You're most likely looking for query batching? To make everything in a single round trip?
r

rocketraman

05/10/2021, 4:00 PM
Yup
m

mbonnin

05/10/2021, 4:01 PM
This issue has been opened for a while 🙈
r

rocketraman

05/10/2021, 4:01 PM
Though some backends will actually put multiple mutations sent in a request into a single transaction. For example, Hasura.
m

mbonnin

05/10/2021, 4:02 PM
Yea, this is kind of the point, right?
r

rocketraman

05/10/2021, 4:02 PM
Well, that's not specified by the gql spec afaik, so I guess its implementation specific.
👍 1
Do you have a pointer to the issue?
m

mbonnin

05/10/2021, 4:03 PM
Yep but if the backend doesn't do any optimization, I was under the impression that using HTTP2 pipelining would reduce latency without any increased network overhead?
Overall, query batching a double edge sword because your mutation become as slow (or fast) as the slowest mutation in the batch
r

rocketraman

05/10/2021, 4:10 PM
Makes sense about HTTP2 pipelining, where supported at least. Yeah, understood about the batching -- my case will require
async
and
awaitAll
anyway.
Do you know what sav007 means by:
And with client batching (via aliases) seems to me like a workaround.
m

mbonnin

05/10/2021, 4:15 PM
I'm guessing the idea was to merge the queries client side and use aliases if requesting two fields with the same name
r

rocketraman

05/10/2021, 4:16 PM
Ah. Yeah, obviously not a solution for mutations.
m

mbonnin

05/10/2021, 4:16 PM
About the hasura use case, what about a big mutation?
mutation {
  updateUser() {}
  addPost() {}
  ...
}
You can request any number of root fields in a mutation
r

rocketraman

05/10/2021, 4:18 PM
I need to do the same mutation multiple times e.g.:
mutation {
  updateUser() {}
  updateUser() {}
  ...
}
And its a list of unknown length
m

mbonnin

05/10/2021, 4:18 PM
Aliases would fix the "multiple times" thing
mutation {
  user1: updateUser() {}
  user2: updateUser() {}
  ...
}
Not the "arbitrary length" thing
r

rocketraman

05/10/2021, 4:19 PM
Yup, and passing in the parameters for that is annoying, as I need to alias all of those too.
👍 1
m

mbonnin

05/10/2021, 4:20 PM
Yep. Usually, I would expect a mutation that takes a list of inputs there:
mutation($inputs: [UserInputs]) {
  updateUsers($inputs)
}
r

rocketraman

05/10/2021, 4:21 PM
Yeah, Hasura supports inserts with that model. Let me check if they can do updates like that too...
👍 1
No, only a
where
parameter to update multiple, and it has to be the same update for all matching rows.