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

Add Support for Batching Mutations #517

Open
ricbermo opened this issue Apr 28, 2023 · 3 comments
Open

Add Support for Batching Mutations #517

ricbermo opened this issue Apr 28, 2023 · 3 comments

Comments

@ricbermo
Copy link

Perceived Problem

I was trying to delete multiple records at once but I noticed my "documents" are sent as queries

const requests = uuids.map((uuid: string) => ({
  document: deleteRecordById,
    variables: {uuid},
  }));
await client.batchRequests(requests);

// export const deleteRecordById = `
mutation deleteRecordById($uuid: ID!) {
  deleteRecordById(id: $uuid) {
    id
  }
}`;

Ideas / Proposed Solution(s)

It'd be nice to let batchRequests work for mutations as well.
For now, this is what I did

const request = uuids.map((uuid: string) =>
  client.request(deleteChildAthleteById, {uuid}),
);
await Promise.all(request);

Thanks

@DanielAtCosmicDNA
Copy link

For the time being one can use:

const batchRequests = async (requests) => Promise.all(requests.map((request) => mutationClient.request(request.document, request.variables)))

@goleary
Copy link

goleary commented Jun 26, 2023

The downside with this workaround is that it's not really batching requests since multiple requests are sent albeit in parallel.

@DanielAtCosmicDNA
Copy link

The downside with this workaround is that it's not really batching requests since multiple requests are sent albeit in parallel.

The idea is to use this in the meanwhile there is no graphql-request working feature that contemplates batching mutations. Once graphql-request develops the feature, it is just the matter of using graphql-request's batchRequests as a drop-in replacement for this workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants