Skip to content

Conversation

@phryneas
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Aug 19, 2025

🦋 Changeset detected

Latest commit: 0b00e09

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-codemod-migrate-3-to-4 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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 19, 2025

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.89 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.72 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.83 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 27.01 KB (0%)
import { ApolloProvider } from "@apollo/client/react" 5.91 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 970 B (0%)
import { useQuery } from "@apollo/client/react" 7.22 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 2.23 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 7.1 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.14 KB (0%)
import { useMutation } from "@apollo/client/react" 6.46 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 1.48 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.77 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 1.79 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.58 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.62 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.32 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.38 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.28 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.36 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.58 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.63 KB (0%)
import { useFragment } from "@apollo/client/react" 6.65 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.71 KB (0%)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 19, 2025

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

commit: 0b00e09

@apollo-librarian
Copy link

apollo-librarian bot commented Aug 19, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

32 new, 64 changed, 7 removed
+ (developer-tools)/react/(latest)/api/link/apollo-link-base-batch-http.mdx
+ (developer-tools)/react/(latest)/api/link/apollo-link-base-http.mdx
+ (developer-tools)/react/(latest)/api/link/apollo-link-batch.mdx
+ (developer-tools)/react/(latest)/api/link/apollo-link-client-awareness.mdx
+ (developer-tools)/react/(latest)/api/link/apollo-link-persisted-queries.mdx
+ (developer-tools)/react/(latest)/api/link/apollo-link.mdx
+ (developer-tools)/react/(latest)/api/react/ApolloProvider.mdx
+ (developer-tools)/react/(latest)/api/react/skipToken.mdx
+ (developer-tools)/react/(latest)/api/react/useApolloClient.mdx
+ (developer-tools)/react/(latest)/api/react/useBackgroundQuery.mdx
+ (developer-tools)/react/(latest)/api/react/useFragment.mdx
+ (developer-tools)/react/(latest)/api/react/useLazyQuery.mdx
+ (developer-tools)/react/(latest)/api/react/useLoadableQuery.mdx
+ (developer-tools)/react/(latest)/api/react/useMutation.mdx
+ (developer-tools)/react/(latest)/api/react/useQuery.mdx
+ (developer-tools)/react/(latest)/api/react/useQueryRefHandlers.mdx
+ (developer-tools)/react/(latest)/api/react/useReactiveVar.mdx
+ (developer-tools)/react/(latest)/api/react/useReadQuery.mdx
+ (developer-tools)/react/(latest)/api/react/useSubscription.mdx
+ (developer-tools)/react/(latest)/api/react/useSuspenseQuery.mdx
+ (developer-tools)/react/(latest)/api/errors/CombinedGraphQLErrors.mdx
+ (developer-tools)/react/(latest)/api/errors/CombinedProtocolErrors.mdx
+ (developer-tools)/react/(latest)/api/errors/LinkError.mdx
+ (developer-tools)/react/(latest)/api/errors/LocalStateError.mdx
+ (developer-tools)/react/(latest)/api/errors/ServerError.mdx
+ (developer-tools)/react/(latest)/api/errors/ServerParseError.mdx
+ (developer-tools)/react/(latest)/api/errors/UnconventionalError.mdx
+ (developer-tools)/react/(latest)/data/persisted-queries.mdx
+ (developer-tools)/react/(latest)/data/typescript.mdx
+ (developer-tools)/react/(latest)/development-testing/graphql-codegen.mdx
+ (developer-tools)/react/(latest)/VERSIONING_POLICY.md
+ (developer-tools)/react/(latest)/versioning-policy.md
* (developer-tools)/react/(latest)/get-started.mdx
* (developer-tools)/react/(latest)/index.mdx
* (developer-tools)/react/(latest)/why-apollo.mdx
* (developer-tools)/react/(latest)/api/cache/InMemoryCache.mdx
* (developer-tools)/react/(latest)/api/core/ApolloClient.mdx
* (developer-tools)/react/(latest)/api/core/ObservableQuery.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-batch-http.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-context.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-error.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-http.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-remove-typename.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-retry.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-schema.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-subscriptions.mdx
* (developer-tools)/react/(latest)/api/link/apollo-link-ws.mdx
* (developer-tools)/react/(latest)/api/link/community-links.mdx
* (developer-tools)/react/(latest)/api/link/introduction.mdx
* (developer-tools)/react/(latest)/api/react/hooks.mdx
* (developer-tools)/react/(latest)/api/react/preloading.mdx
* (developer-tools)/react/(latest)/api/react/ssr.mdx
* (developer-tools)/react/(latest)/api/react/testing.mdx
* (developer-tools)/react/(latest)/caching/advanced-topics.mdx
* (developer-tools)/react/(latest)/caching/cache-configuration.mdx
* (developer-tools)/react/(latest)/caching/cache-field-behavior.mdx
* (developer-tools)/react/(latest)/caching/cache-interaction.mdx
* (developer-tools)/react/(latest)/caching/garbage-collection.mdx
* (developer-tools)/react/(latest)/caching/memory-management.mdx
* (developer-tools)/react/(latest)/caching/overview.mdx
* (developer-tools)/react/(latest)/data/defer.mdx
* (developer-tools)/react/(latest)/data/directives.mdx
* (developer-tools)/react/(latest)/data/document-transforms.mdx
* (developer-tools)/react/(latest)/data/error-handling.mdx
* (developer-tools)/react/(latest)/data/file-uploads.mdx
* (developer-tools)/react/(latest)/data/fragments.mdx
* (developer-tools)/react/(latest)/data/mutations.mdx
* (developer-tools)/react/(latest)/data/operation-best-practices.mdx
* (developer-tools)/react/(latest)/data/queries.mdx
* (developer-tools)/react/(latest)/data/refetching.mdx
* (developer-tools)/react/(latest)/data/subscriptions.mdx
* (developer-tools)/react/(latest)/data/suspense.mdx
* (developer-tools)/react/(latest)/development-testing/client-schema-mocking.mdx
* (developer-tools)/react/(latest)/development-testing/developer-tooling.mdx
* (developer-tools)/react/(latest)/development-testing/schema-driven-testing.mdx
* (developer-tools)/react/(latest)/development-testing/testing.mdx
* (developer-tools)/react/(latest)/integrations/integrations.mdx
* (developer-tools)/react/(latest)/integrations/react-native.mdx
* (developer-tools)/react/(latest)/integrations/webpack.mdx
* (developer-tools)/react/(latest)/local-state/local-resolvers.mdx
* (developer-tools)/react/(latest)/local-state/local-state-management.mdx
* (developer-tools)/react/(latest)/local-state/managing-state-with-field-policies.mdx
* (developer-tools)/react/(latest)/local-state/reactive-variables.mdx
* (developer-tools)/react/(latest)/migrating/apollo-client-3-migration.mdx
* (developer-tools)/react/(latest)/networking/advanced-http-networking.mdx
* (developer-tools)/react/(latest)/networking/authentication.mdx
* (developer-tools)/react/(latest)/networking/basic-http-networking.mdx
* (developer-tools)/react/(latest)/pagination/core-api.mdx
* (developer-tools)/react/(latest)/pagination/cursor-based.mdx
* (developer-tools)/react/(latest)/pagination/key-args.mdx
* (developer-tools)/react/(latest)/pagination/offset-based.mdx
* (developer-tools)/react/(latest)/performance/babel.mdx
* (developer-tools)/react/(latest)/performance/optimistic-ui.mdx
* (developer-tools)/react/(latest)/performance/performance.mdx
* (developer-tools)/react/(latest)/performance/server-side-rendering.mdx
* (developer-tools)/react/(latest)/_sidebar.yaml
- (developer-tools)/react/(latest)/api/link/apollo-link-rest.mdx
- (developer-tools)/react/(latest)/api/link/persisted-queries.mdx
- (developer-tools)/react/(latest)/api/react/components.mdx
- (developer-tools)/react/(latest)/api/react/hoc.mdx
- (developer-tools)/react/(latest)/development-testing/static-typing.mdx
- (developer-tools)/react/(latest)/local-state/client-side-schema.mdx
- (developer-tools)/react/(latest)/migrating/hooks-migration.mdx

Build ID: 65226bf5d5f9206282bf39b3
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/65226bf5d5f9206282bf39b3

@phryneas phryneas changed the title add apolloClientInitialization codemod add clientSetup codemod Aug 20, 2025
}
const enabledStepNames =
Array.isArray(options.apolloClientInitialization) ?
options.apolloClientInitialization
Copy link
Member Author

Choose a reason for hiding this comment

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

This option is only meant for our tests to enable individual codemods, not for end users, that would get too granular.

Comment on lines +102 to +118
/*
Start: Inserted by Apollo Client 3->4 migration codemod.
Copy the contents of this block into a \`.d.ts\` file in your project
to enable data masking types.
*/
import "@apollo/client";
import { GraphQLCodegenDataMasking } from "@apollo/client/masking";
declare module "@apollo/client" {
export interface TypeOverrides extends GraphQLCodegenDataMasking.TypeOverrides {}
}
/*
End: Inserted by Apollo Client 3->4 migration codemod.
*/
Copy link
Member Author

@phryneas phryneas Aug 20, 2025

Choose a reason for hiding this comment

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

This is inserted at the end of the file if dataMasking: true is detected in the options and it is a .ts/.tsx file.

The dataMasking: true gets an additional comment like

        /*
        Inserted by Apollo Client 3->4 migration codemod.
        Keep this comment here if you intend to run the codemod again,
        to avoid changes from being reapplied.
        Delete this comment once you are done with the migration.
        @apollo/client-codemod-migrate-3-to-4 applied
        */
        dataMasking: true,

and as long as at least

        /* @apollo/client-codemod-migrate-3-to-4 applied */
        dataMasking: true,

stays in place, this will not be added to the file a second time when rerunning the codemod, even if the user deletes the block or moves it out into a separate file as instructed.

Comment on lines +121 to +138
/*
Start: Inserted by Apollo Client 3->4 migration codemod.
Copy the contents of this block into a \`.d.ts\` file in your project to enable correct response types in your custom links.
If you do not use the \`@defer\` directive in your application, you can safely remove this block.
*/
import "@apollo/client";
import { Defer20220824Handler } from "@apollo/client/incremental";
declare module "@apollo/client" {
export interface TypeOverrides extends Defer20220824Handler.TypeOverrides {}
}
/*
End: Inserted by Apollo Client 3->4 migration codemod.
*/"
`);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is added at the end of the file if incrementalHandler was not present in the options previously and it is a .ts/.tsx file.

Comment on lines +94 to +99
/*
Inserted by Apollo Client 3->4 migration codemod.
If you are not using the \`@defer\` directive in your application,
you can safely remove this option.
*/
incrementalHandler: new Defer20220824Handler()
Copy link
Member Author

Choose a reason for hiding this comment

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

This will be added if no incrementalHandler option is found.

Comment on lines +482 to +487
/*
Inserted by Apollo Client 3->4 migration codemod.
If you are not using the \`@client\` directive in your application,
you can safely remove this option.
*/
localState: new LocalState({})
Copy link
Member Author

Choose a reason for hiding this comment

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

If no resolvers option is found, a localState option will be added anyways, but then it has this preceding comment telling the user to delete it if they don't use @client directives.

That seemed preferrable to me over users missing out on getting it added by the codemod.

Comment on lines +26 to +30
uri: "/graphql",
credentials: "include",
headers: {
"x-custom-header": "value",
},
Copy link
Member Author

Choose a reason for hiding this comment

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

moving into link

cache: new InMemoryCache(),
ssrForceFetchDelay: 50,
ssrMode: true,
connectToDevTools: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

renamed to devTools.enabled

defaultOptions: {},
defaultContext: {},
assumeImmutableResults: true,
resolvers: myResolvers,
Copy link
Member Author

Choose a reason for hiding this comment

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

moving into localState

Comment on lines +40 to +41
typeDefs: mySchema,
fragmentMatcher: () => true,
Copy link
Member Author

Choose a reason for hiding this comment

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

these are removed

Comment on lines +42 to +43
name: "my-client",
version: "1.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

moving into clientAwareness

@phryneas phryneas requested a review from jerelmiller August 20, 2025 12:27
@phryneas phryneas marked this pull request as ready for review August 20, 2025 12:28
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

let's get it in

@github-actions github-actions bot added the auto-cleanup 🤖 label Aug 20, 2025
@jerelmiller jerelmiller merged commit 32bc830 into release-4.0 Aug 20, 2025
44 checks passed
@jerelmiller jerelmiller deleted the pr/ac-init-codemod branch August 20, 2025 21:08
@github-actions github-actions bot mentioned this pull request Aug 20, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 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.

3 participants