Skip to content

Cannot resolve multiple parallel mutations from same createMutation call #15

@JoosepAlviste

Description

@JoosepAlviste

Hey, many thanks for this library!

I ran into an issue when trying to trigger multiple mutations in parallel with different variables.

Here's an example of what I mean:

const [mutate] = createMutation(MUTATION);

const res = await Promise.all([
  mutate({ variables: { id: "1" } }),
  mutate({ variables: { id: "2" } }),
]);

The Promise.all does not get resolved, because only the last mutation promise is resolved.

I also reproduced the issue here: https://codesandbox.io/s/misty-snow-6fhw59?file=/src/App.jsx

I see here https://github.com/merged-js/solid-apollo/blob/main/src/createMutation.ts#L64 that resolveResultPromise is overwritten any time the mutate function is called.

I'm not sure what a good approach would be to fix this. Maybe the resolve and reject promises kept track of could instead be arrays so that each new call to mutate would add its own promises to the arrays and then remember the index of the call?

I wouldn't mind trying to set up a PR, but I'm not quite sure what the best approach would be to resolve the issue since the returned resource still needs to keep working somehow.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions