|
1 | 1 | import type { MatcherFunction } from 'expect';
|
2 | 2 | import type { DocumentNode } from 'graphql';
|
3 |
| -import type { ApolloClient, OperationVariables } from '../../core/index.js'; |
4 |
| -import { SuspenseCache } from '../../react/index.js'; |
| 3 | +import type { OperationVariables } from '../../core/index.js'; |
| 4 | +import { ApolloClient } from '../../core/index.js'; |
5 | 5 | import { canonicalStringify } from '../../cache/index.js';
|
| 6 | +import { getSuspenseCache } from '../../react/cache/index.js'; |
| 7 | +import type { CacheKey } from '../../react/cache/types.js'; |
6 | 8 |
|
7 | 9 | export const toHaveSuspenseCacheEntryUsing: MatcherFunction<
|
8 | 10 | [
|
9 |
| - client: ApolloClient<unknown>, |
10 | 11 | query: DocumentNode,
|
11 | 12 | options: {
|
12 | 13 | variables?: OperationVariables;
|
13 | 14 | queryKey?: string | number | any[];
|
14 | 15 | }
|
15 | 16 | ]
|
16 | 17 | > = function (
|
17 |
| - suspenseCache, |
18 | 18 | client,
|
19 | 19 | query,
|
20 | 20 | { variables, queryKey = [] } = Object.create(null)
|
21 | 21 | ) {
|
22 |
| - if (!(suspenseCache instanceof SuspenseCache)) { |
23 |
| - throw new Error('Actual must be an instance of `SuspenseCache`'); |
| 22 | + if (!(client instanceof ApolloClient)) { |
| 23 | + throw new Error('Actual must be an instance of `ApolloClient`'); |
24 | 24 | }
|
25 | 25 |
|
26 |
| - const cacheKey = ( |
27 |
| - [client, query, canonicalStringify(variables)] as any[] |
28 |
| - ).concat(queryKey); |
| 26 | + const suspenseCache = getSuspenseCache(client); |
| 27 | + |
| 28 | + const cacheKey: CacheKey = [ |
| 29 | + query, |
| 30 | + canonicalStringify(variables), |
| 31 | + ...([] as any[]).concat(queryKey), |
| 32 | + ]; |
29 | 33 | const queryRef = suspenseCache['queryRefs'].lookupArray(cacheKey)?.current;
|
30 | 34 |
|
31 | 35 | return {
|
|
0 commit comments