Skip to content

Conversation

@jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Mar 25, 2025

Closes #12456
Closes #12422
Closes #12427

Changes the type emitted from subscriptions to a SubscribeResult, which uses error instead of errors. This change also unifies the error behavior between GraphQL errors and network errors so that network errors adhere to the configured errorPolicy. This change means that results are no longer emitted when using errorPolicy: 'ignore' if there is no associated data as well so that we avoid emitting an empty value.

This change also no longer terminates the downstream connection when encountering an error. If the downstream connection closes as a result of the error, a next event will be followed by a complete event instead. This change essentially means that using the error callback is useless and no longer needed. This change allows for additional results to be emitted from the subscription if the subscription remains open after errors are emitted.

@changeset-bot
Copy link

changeset-bot bot commented Mar 25, 2025

🦋 Changeset detected

Latest commit: b474106

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 25, 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: be694db40e57891bae5e7a0f

@jerelmiller jerelmiller changed the base branch from release-4.0 to jerel/update-mutation-and-error-result-types March 25, 2025 00:13
@jerelmiller jerelmiller marked this pull request as draft March 25, 2025 00:13
@jerelmiller jerelmiller force-pushed the jerel/update-mutation-and-error-result-types branch from 4e25df0 to c79b5bd Compare March 25, 2025 03:13
@jerelmiller jerelmiller force-pushed the jerel/update-subscription-type-and-errors branch from 0ce183c to f75f867 Compare March 25, 2025 03:13
@jerelmiller jerelmiller changed the title [WIP] Unify subscription error behavior and update emitted type Unify subscription error behavior and update emitted type Mar 25, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 25, 2025

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

commit: b474106

@jerelmiller jerelmiller requested a review from phryneas March 25, 2025 04:10
@jerelmiller jerelmiller marked this pull request as ready for review March 25, 2025 04:10
@jerelmiller jerelmiller force-pushed the jerel/update-mutation-and-error-result-types branch from c79b5bd to 7a5edf4 Compare March 27, 2025 18:36
@jerelmiller jerelmiller force-pushed the jerel/update-subscription-type-and-errors branch from 046e148 to 13a3fc6 Compare March 27, 2025 18:38
@jerelmiller jerelmiller force-pushed the jerel/update-mutation-and-error-result-types branch from 7a5edf4 to 9e97db8 Compare March 27, 2025 22:00
@jerelmiller jerelmiller force-pushed the jerel/update-subscription-type-and-errors branch from 13a3fc6 to f4076c8 Compare March 27, 2025 22:01
@jerelmiller jerelmiller force-pushed the jerel/update-mutation-and-error-result-types branch from 9e97db8 to 6b1bfc8 Compare March 28, 2025 16:32
@jerelmiller jerelmiller force-pushed the jerel/update-subscription-type-and-errors branch from f4076c8 to cf30381 Compare March 28, 2025 16:35
if (onError) {
onError(error);
} else {
invariant.error("Unhandled GraphQL subscription error", error);
Copy link
Member

Choose a reason for hiding this comment

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

invariant.error will only display in dev and only log, not throw - do we want that behaviour to be dev-only?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think its ok to leave as dev-only. I'm guessing the original intent here was to let someone know that an error occurred that isn't handled since the error would otherwise get swallowed. I think I'm ok leaving this as a dev-only check since its more of a "warning" that you might want to do something to handle the error.

Base automatically changed from jerel/update-mutation-and-error-result-types to release-4.0 March 31, 2025 14:41
@jerelmiller jerelmiller force-pushed the jerel/update-subscription-type-and-errors branch from cf30381 to b474106 Compare March 31, 2025 14:42
@netlify
Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit b474106
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67eaa9d71b04f5000852f43e
😎 Deploy Preview https://deploy-preview-12476--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

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 41.32 KB (+0.31% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 36.81 KB (+0.09% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 31.97 KB (+0.32% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.94 KB (+0.19% 🔺)
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 (0%)
import { useMutation } from "@apollo/client/react" (production) 2.11 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.74 KB (-1.32% 🔽)
import { useSubscription } from "@apollo/client/react" (production) 2.49 KB (-4.89% 🔽)
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 merged commit 6afff60 into release-4.0 Mar 31, 2025
49 checks passed
@jerelmiller jerelmiller deleted the jerel/update-subscription-type-and-errors branch March 31, 2025 15:14
@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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants