Skip to content

Conversation

@jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Mar 24, 2025

Closes #12455
Fixes #9065
Fixes #7167
Partially addresses #12427

Updates client.mutate to return a MutateResult type instead of a FetchResult. FetchResult is the raw response type we expect from the link chain. Because of this, we were not able to apply error unification to mutations since there is no error property on this type.

This change swaps errors for error and applies the same error unification behavior to mutations as was done to queries in #12457. Network errors are now subject to the errorPolicy and will resolve the mutation promise if the errorPolicy is not none.

This change also fixes a long-standing bug with useMutation where passing an onError callback would resolve the promise returned from the mutation when errorPolicy was none. These errors are now rejected to ensure the mutation behaves the same whether or not onError was provided.

@jerelmiller jerelmiller requested a review from phryneas March 24, 2025 21:26
@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2025

🦋 Changeset detected

Latest commit: e2c12e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svc-apollo-docs
Copy link

svc-apollo-docs commented Mar 24, 2025

⚠️ Docs preview not attached to branch

The preview was not built because the PR's base branch release-4.0 is not in the list of sources.

An Apollo team member can comment one of the following commands to dictate which branch to attach the preview to:

  • !docs set-base-branch version-2.6
  • !docs set-base-branch main

Build ID: 8e25f55327a8bb5901a48b8c

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 24, 2025

npm i https://pkg.pr.new/@apollo/client@12475

commit: e2c12e1

@netlify
Copy link

netlify bot commented Mar 24, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit e2c12e1
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67eaa8893e7e3f000896e17b
😎 Deploy Preview https://deploy-preview-12475--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 41.2 KB (-0.06% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 36.78 KB (+0.25% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 31.87 KB (+0.12% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.89 KB (+0.13% 🔺)
import { ApolloProvider } from "@apollo/client/react" 5.17 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 960 B (0%)
import { useQuery } from "@apollo/client/react" 6.99 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 2.76 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 6.39 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.17 KB (0%)
import { useMutation } from "@apollo/client/react" 6.34 KB (-1.91% 🔽)
import { useMutation } from "@apollo/client/react" (production) 2.11 KB (-5.44% 🔽)
import { useSubscription } from "@apollo/client/react" 6.83 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 2.62 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.21 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 4 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.06 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.83 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.06 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.87 KB (0%)
import { useReadQuery } from "@apollo/client/react" 5.83 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.61 KB (0%)
import { useFragment } from "@apollo/client/react" 5.89 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.66 KB (0%)

@jerelmiller jerelmiller changed the title Update type of client.mutate type of client.mutate Mar 25, 2025
@jerelmiller jerelmiller changed the title type of client.mutate Unify error behavior of client.mutate and update its type Mar 25, 2025
@jerelmiller jerelmiller force-pushed the jerel/update-mutation-and-error-result-types branch 3 times, most recently from 7a5edf4 to 9e97db8 Compare March 27, 2025 22:00
@jerelmiller jerelmiller force-pushed the jerel/update-mutation-and-error-result-types branch from 9e97db8 to 6b1bfc8 Compare March 28, 2025 16:32
Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change, let's get this in!

@github-actions github-actions bot added the auto-cleanup 🤖 label Mar 31, 2025
@jerelmiller jerelmiller merged commit 3de63eb into release-4.0 Mar 31, 2025
47 checks passed
@jerelmiller jerelmiller deleted the jerel/update-mutation-and-error-result-types branch March 31, 2025 14:41
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants