Skip to content

Improve operation type for SetContextLink #12742

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

Merged
merged 19 commits into from
Jun 27, 2025

Conversation

jerelmiller
Copy link
Member

This is something I noticed when converting a different app. The operation argument given to the callback in SetContextLink was a GraphQLRequest type which included the context property. This property was always undefined so using it could result in bugs when really you should be using the prevContext argument instead.

This PR adjusts the type to ensure context is not part of the type. This PR also adds the client property from the operation so that its accessible like other links.

@jerelmiller jerelmiller requested a review from phryneas June 25, 2025 18:12
Copy link

changeset-bot bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: b787b47

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

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

Copy link

pkg-pr-new bot commented Jun 25, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@12742
npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client-codemod-migrate-3-to-4@12742

commit: b787b47

Copy link
Contributor

github-actions bot commented Jun 25, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.62 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.73 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.55 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.97 KB (0%)
import { ApolloProvider } from "@apollo/client/react" 5.7 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 960 B (0%)
import { useQuery } from "@apollo/client/react" 7.48 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 2.72 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 6.95 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.19 KB (0%)
import { useMutation } from "@apollo/client/react" 6.52 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 1.75 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.63 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 1.86 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.49 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.73 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.22 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.5 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.54 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.81 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.45 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.68 KB (0%)
import { useFragment } from "@apollo/client/react" 6.49 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.74 KB (0%)

@@ -17,5 +17,5 @@ export function transformOperation(operation: GraphQLRequest): GraphQLRequest {
: "";
}

return transformedOperation as Operation;
return transformedOperation;
Copy link
Member

Choose a reason for hiding this comment

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

Semi-related - this seems to strip out operationType, which we actually want to preserve.

Copy link
Member

Choose a reason for hiding this comment

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

See #12748

Copy link
Member Author

Choose a reason for hiding this comment

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

Really good catch on that. I removed the type cast since the function had an explicit return and now I'm glad I made some noise in this file 😆

@github-actions github-actions bot added the auto-cleanup 🤖 label Jun 27, 2025
@jerelmiller jerelmiller requested a review from phryneas June 27, 2025 15:23
@jerelmiller jerelmiller merged commit 575bf3e into release-4.0 Jun 27, 2025
42 of 43 checks passed
@jerelmiller jerelmiller deleted the jerel/update-set-context-link branch June 27, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants