-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add suspenseCache as a lazy hidden property on ApolloClient #11053
Merged
jerelmiller
merged 9 commits into
release-3.8
from
pr/experiment-suspenseCache-on-client
Jul 13, 2023
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e4122f8
Add suspenseCache as a lazy hidden property on ApolloClient
phryneas 85b0f6d
changeset
phryneas c6491c2
tests, cleaning up the PR
phryneas c45906d
Merge remote-tracking branch 'origin/release-3.8' into pr/experiment-…
phryneas b86ce80
some reorganization
phryneas 8070ba1
size-limit
phryneas a012747
cleanup
phryneas fec7fda
Update error message on custom matcher to be the correct class.
jerelmiller 86a0ccd
Merge branch 'release-3.8' into pr/experiment-suspenseCache-on-client
jerelmiller File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
'@apollo/client': patch | ||
--- | ||
|
||
Add `SuspenseCache` as a lazy hidden property on ApolloClient. | ||
This means that `SuspenseCache` is now an implementation details of Apollo Client | ||
and you no longer need to manually instantiate it and no longer need to pass it | ||
into `ApolloProvider`. | ||
Trying to instantiate a `SuspenseCache` instance in your code will now throw an | ||
error. | ||
|
||
Migration: | ||
```diff | ||
-import { SuspenseCache } from '@apollo/client'; | ||
|
||
-const suspenseCache = new SuspenseCache(); | ||
|
||
-<ApolloProvider client={client} suspenseCache={suspenseCache} />; | ||
+<ApolloProvider client={client} />; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { SuspenseCacheOptions } from './index.js'; | ||
import { SuspenseCache } from './SuspenseCache.js'; | ||
import type { ApolloClient } from '../../core/ApolloClient.js'; | ||
|
||
declare module '../../core/ApolloClient.js' { | ||
interface DefaultOptions { | ||
react?: { | ||
suspense?: Readonly<SuspenseCacheOptions>; | ||
}; | ||
} | ||
} | ||
|
||
const suspenseCacheSymbol = Symbol.for('apollo.suspenseCache'); | ||
|
||
export function getSuspenseCache( | ||
client: ApolloClient<object> & { | ||
[suspenseCacheSymbol]?: SuspenseCache; | ||
} | ||
) { | ||
if (!client[suspenseCacheSymbol]) { | ||
client[suspenseCacheSymbol] = new SuspenseCache( | ||
client.defaultOptions.react?.suspense | ||
); | ||
} | ||
|
||
return client[suspenseCacheSymbol]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
export { SuspenseCache } from './SuspenseCache.js'; | ||
export type { SuspenseCacheOptions } from './SuspenseCache.js'; | ||
export { getSuspenseCache } from './getSuspenseCache.js'; | ||
|
||
import { SuspenseCache as RealSuspenseCache } from './SuspenseCache.js'; | ||
|
||
// TODO: remove export with release 3.8 | ||
// replace with | ||
// export type { SuspenseCache } from './SuspenseCache.js'; | ||
/** | ||
* @deprecated | ||
* It is no longer necessary to create a `SuspenseCache` instance and pass it into the `ApolloProvider`. | ||
* Please remove this code from your application. | ||
* | ||
* This export will be removed with the final 3.8 release. | ||
*/ | ||
export class SuspenseCache extends RealSuspenseCache { | ||
constructor(){ | ||
super(); | ||
// throwing an error here instead of using invariant - we do not want this error | ||
// message to be link-ified, but to directly show up as bold as possible | ||
throw new Error( | ||
'It is no longer necessary to create a `SuspenseCache` instance and pass it into the `ApolloProvider`.\n' + | ||
'Please remove this code from your application. \n\n' + | ||
'This export will be removed with the final 3.8 release.' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export type CacheKey = any[]; | ||
import type { DocumentNode } from "graphql"; | ||
|
||
export type CacheKey = [query: DocumentNode, stringifiedVariables: string, ...queryKey: any[]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, there will not be any export of the
SuspenseCache
class any more, not even Apollo-Client-internally.Instead, we export the
getSuspenseCache
(only for internal use, so it should not end up in any public entry points!) function.