@@ -4,12 +4,16 @@ import {
4
4
unwrapQueryRef ,
5
5
updateWrappedQueryRef ,
6
6
} from "../internal/index.js" ;
7
- import type { QueryReference } from "../internal/index.js" ;
7
+ import type {
8
+ InternalQueryReference ,
9
+ QueryReference ,
10
+ } from "../internal/index.js" ;
8
11
import { __use , wrapHook } from "./internal/index.js" ;
9
12
import { toApolloError } from "./useSuspenseQuery.js" ;
10
13
import { useSyncExternalStore } from "./useSyncExternalStore.js" ;
11
14
import type { ApolloError } from "../../errors/index.js" ;
12
15
import type { NetworkStatus } from "../../core/index.js" ;
16
+ import { useApolloClient } from "./useApolloClient.js" ;
13
17
14
18
export interface UseReadQueryResult < TData = unknown > {
15
19
/**
@@ -39,10 +43,25 @@ export interface UseReadQueryResult<TData = unknown> {
39
43
export function useReadQuery < TData > (
40
44
queryRef : QueryReference < TData >
41
45
) : UseReadQueryResult < TData > {
46
+ const unwrapped = unwrapQueryRef (
47
+ queryRef
48
+ ) satisfies InternalQueryReference < TData > as /*
49
+ by all rules of this codebase, this should never be undefined
50
+ but if `queryRef` is a transported object, it cannot have a
51
+ `QUERY_REFERENCE_SYMBOL` symbol property, so the call above
52
+ will return `undefined` and we want that represented in the type
53
+ */ InternalQueryReference < TData > | undefined ;
54
+
42
55
return wrapHook (
43
56
"useReadQuery" ,
44
57
_useReadQuery ,
45
- unwrapQueryRef ( queryRef ) [ "observable" ]
58
+ unwrapped ?
59
+ unwrapped [ "observable" ]
60
+ // in the case of a "transported" queryRef object, we need to use the
61
+ // client that's available to us at the current position in the React tree
62
+ // that ApolloClient will then have the job to recreate a real queryRef from
63
+ // the transported object
64
+ : useApolloClient ( )
46
65
) ( queryRef ) ;
47
66
}
48
67
0 commit comments