Skip to content
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

Allow ApolloCache implementations to specify default value for assumeImmutableResults client option #10567

Merged
merged 3 commits into from Mar 21, 2023

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Feb 16, 2023

This commit allows the default value of the assumeImmutableResults option to be determined by the cache (any implementation of ApolloCache), which allows our implementation of InMemoryCache to express the safety of assuming assumeImmutableResults is true, unlocking significant performance savings (fewer defensive deep copies of query results), even if assumeImmutableResults is not configured.

Related past PRs/context:

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2023

🦋 Changeset detected

Latest commit: 2b0a20b

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 Minor

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
Member

@alessbell alessbell left a comment

Choose a reason for hiding this comment

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

🎉🎉

throw new InvariantError(
"To initialize Apollo Client, you must specify a 'cache' property " +
"in the options object. \n" +
"For more information, please visit: https://go.apollo.dev/c/docs"
Copy link
Member

Choose a reason for hiding this comment

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

[Not material to this PR but] TIL that shortlink exists

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, and we can add more short links if need be. It would be cool if each error had its own short link with more info.

src/core/QueryInfo.ts Outdated Show resolved Hide resolved
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.

🎉 🎉 🔥 🔥 This looks great! Super simple change that I think will have a nice impact.

This commit allows the default value of the `assumeImmutableResults`
option to be determined by the cache (any implementation of
`ApolloCache`), which allows our implementation of `InMemoryCache` to
express the safety of assuming `assumeImmutableResults` is `true`,
unlocking significant performance savings (fewer defensive deep copies
of query results), even if `assumeImmutableResults` is not configured.

Related past PRs:
- #4543
- #5153
- #9680
- [Apollo Client 2.6 blog post](https://www.apollographql.com/blog/announcement/frontend/whats-new-in-apollo-client-2-6/#rewarding-immutability)
@benjamn benjamn force-pushed the auto-detect-assumeImmutableResults branch from 1e82a21 to 2b0a20b Compare March 21, 2023 22:23
@benjamn benjamn merged commit c2ce649 into release-3.8 Mar 21, 2023
1 check passed
@benjamn benjamn deleted the auto-detect-assumeImmutableResults branch March 21, 2023 22:52
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
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.

None yet

3 participants