Is there a way to send multiple mutations in one r...
# apollo-kotlin
r
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
You're most likely looking for query batching? To make everything in a single round trip?
r
Yup
m
This issue has been opened for a while 🙈
r
Though some backends will actually put multiple mutations sent in a request into a single transaction. For example, Hasura.
m
Yea, this is kind of the point, right?
r
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
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
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
I'm guessing the idea was to merge the queries client side and use aliases if requesting two fields with the same name
r
Ah. Yeah, obviously not a solution for mutations.
m
About the hasura use case, what about a big mutation?
Copy code
mutation {
  updateUser() {}
  addPost() {}
  ...
}
You can request any number of root fields in a mutation
r
I need to do the same mutation multiple times e.g.:
Copy code
mutation {
  updateUser() {}
  updateUser() {}
  ...
}
And its a list of unknown length
m
Aliases would fix the "multiple times" thing
Copy code
mutation {
  user1: updateUser() {}
  user2: updateUser() {}
  ...
}
Not the "arbitrary length" thing
r
Yup, and passing in the parameters for that is annoying, as I need to alias all of those too.
👍 1
m
Yep. Usually, I would expect a mutation that takes a list of inputs there:
Copy code
mutation($inputs: [UserInputs]) {
  updateUsers($inputs)
}
r
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.
257 Views