Skip to content
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

Support for query batching #13

Closed
cameronk opened this issue Jul 26, 2017 · 11 comments · Fixed by #285
Closed

Support for query batching #13

cameronk opened this issue Jul 26, 2017 · 11 comments · Fixed by #285
Milestone

Comments

@cameronk
Copy link

Some GraphQL servers, such as Graphcool, allow the client to batch multiple queries/mutations into one HTTP request by sending an array of GraphQL request objects ({ query, variables }) in the request body.

Given the current implementation I can see two ways of doing this:

  1. Modify GraphQLClient.request to accept both standard arguments (query, variables) and an array of request objects
  2. Create a new method (something like GraphQLClient.batchRequest) that only accepts an array of request objects

I'd be interested to see how error handling would work for batch requests - would an error be thrown for the whole batch request if any one of its child queries/mutations returned an error?

@schickling
Copy link
Contributor

I remember @RomanGotsiy to bring up a similar idea. Let's discuss this here to see whether it should be part of graphql-request.

@lewisblackwood
Copy link

I'd be really interested to find out what's recommended here.

My current scenario is hitting a third party API in a Lambda, retrieving multiple resources, and then wanting to use a batched mutation to create several records in graphcool with graphql-request.

Right now, I'm using string interpolation with template literals to build my request.

I see that the Apollo team don't recommend that.

Is there a better way to do this, passing an array of request objects to graphql-request?

@schickling
Copy link
Contributor

Yes, this sounds like a very common scenario. I'm getting more and more convinced that query batching should be part of graphql-request. It most likely will require a new API design, so I'll line it up for the 2.0 release.

@schickling schickling added this to the 2.0 milestone Aug 10, 2017
@peterpme
Copy link

peterpme commented Sep 1, 2017

I needed to extend graphql-request myself and ported it into its own library: https://github.com/Preposterous/graphql-batching-helpers

It gets the job done but could definitely be more feature-rich

@flybayer
Copy link

I'd also love to have batching support!

@darren128
Copy link

darren128 commented Sep 7, 2018

@schickling Is this going to be a part of 2.0? I can help with the feature if needed, this would be a huge win.

@darren128
Copy link

@schickling I'd still be willing to submit a PR for this feature if someone is willing to review it.

@pyramation
Copy link

@darren128 I'll help review, I'm not an official contributor, but the feature would be great and I'm sure we'd all appreciate a PR for this :)

@darren128
Copy link

@pyramation Sounds good, I'll put something together then.

@kuksik
Copy link

kuksik commented Jul 8, 2021

this feature will be very useful

@jasonkuhrt
Copy link
Member

jasonkuhrt commented Jul 9, 2021

The GraphQL spec already allows in theory sending whole graphql documents with multiple operations therein.

It should be relatively simple to make the client able to incrementally define a document to send.

PRs welcome.

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

Successfully merging a pull request may close this issue.

9 participants