It would be awesome if we could detect batch operations based on a header and then parse the incoming request as an array of operations or a single operation.
This is a really really ugly proof of concept, but it actually works.
https://gist.github.com/macnibblet/8c25cd7964c6c28fe09c40126424032c
Things one probably wants to take into account is the number of concurrent operations running.
I'm thinking a worker pool per request is probably a better solution, but not entirely sure.
Secondly, I have no idea how the tracing gets affected by this code.
Thirdly, No mutexes around the responses slice, https://stackoverflow.com/questions/49879322/can-i-concurrently-write-different-slice-elements not sure if it's a good idea but too lazy to abstract away the boilerplate
Thanks @macnibblet โ this is a great reference for anyone that is interested in implementing this now. It does highlight that handler could probably do with a refactor to make it a bit more swappable.
@mathewbyrne If someone can confirm the tracing works with the way I have implemented it now I have no problem turning it from a proof of concept to production worthy code.
I could use this in production for a few applications we are running with this awesome library.
@vektah Do you have any comments on how the tracing should work when batching? Else ill update my POC and create a merge request.
I don't think batching can happen concurrently without a bit more work to establish sync boundaries.
Consider a batch that looks like this:
query q1 { user(id: 1) {name} }
mutation m1 { setName(id: 1, name: "foo") { name } }
query q2 { user(id: 1) {name} }
mutation m2 { setName(id: 1, name: "bar") { name } }
query q3 { user(id: 1) {name} }
I would expect to get back
q1: "previous"
m1: "foo"
q2: "foo"
m2: "bar"
p3: "bar"
The suggested implementation would likely do something very different.
I'm not sure how apollo tracing + batching should work, someone would need to fire up a server and have a look at whats in the extensions. It probably keeps each req/resp separate.
Also make sure you base any work on the next branch, rebasing between the two is painful.
@vektah AFAIK you are not allowed to mix queries and mutations?
Regards to the tracing, do we want to split each operation into a single request or have them under the same request?
@vektah AFAIK you are not allowed to mix queries and mutations?
Ahh right, lets make sure we have some validation covering that.
Regards to the tracing, do we want to split each operation into a single request or have them under the same request?
I think that makes sense, still worth having a look at what apollo server does with tracing turned on. apollo tracing is returned in the extensions key of the response, so I imagine its per query/mutation.
We're interested in this feature too. Happy to collaborate on an implementation.
Hi everyone, I'm also interested in this feature ๐
Any news on the advancement?
Thank you,
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
No stale.
Interested in this as well
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Nope, stale.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still interested ๐
Can we disable stale for some issues?
Would this be easier given the recent handler refactor?
yeah would love to see this as well!
I'm interested in funding/sponsoring this enhancement. I'm not sure how it would work through the 99designs organization but happy to work with individuals directly. If anyone else is interested in pitching in, add an ๐ reaction!
I would like this feature as well. To work better with the nautilus gateway batching https://gateway.nautilus.dev/advanced/batching
Most helpful comment
I'm interested in funding/sponsoring this enhancement. I'm not sure how it would work through the 99designs organization but happy to work with individuals directly. If anyone else is interested in pitching in, add an ๐ reaction!