diff --git a/src/react/cache/QueryReference.ts b/src/react/cache/QueryReference.ts index 5b2fc14c643..b4069fa9f36 100644 --- a/src/react/cache/QueryReference.ts +++ b/src/react/cache/QueryReference.ts @@ -12,7 +12,7 @@ import { createFulfilledPromise, createRejectedPromise, } from "../../utilities/index.js"; -import type { CacheKey } from "./types.js"; +import type { CacheKey, QueryKey } from "./types.js"; import type { useBackgroundQuery, useReadQuery } from "../hooks/index.js"; type Listener = (promise: Promise>) => void; @@ -65,10 +65,10 @@ type ObservedOptions = Pick< export class InternalQueryReference { public result: ApolloQueryResult; - public readonly key: CacheKey; + public readonly key: QueryKey = {}; public readonly observable: ObservableQuery; - public promiseCache?: Map>>; + public promiseCache?: Map>>; public promise: Promise>; private subscription: ObservableSubscription; @@ -92,7 +92,6 @@ export class InternalQueryReference { // Don't save this result as last result to prevent delivery of last result // when first subscribing this.result = observable.getCurrentResult(false); - this.key = options.key; if (options.onDispose) { this.onDispose = options.onDispose; diff --git a/src/react/cache/types.ts b/src/react/cache/types.ts index e9e0ba8b826..40f3c4cc8fc 100644 --- a/src/react/cache/types.ts +++ b/src/react/cache/types.ts @@ -5,3 +5,7 @@ export type CacheKey = [ stringifiedVariables: string, ...queryKey: any[], ]; + +export interface QueryKey { + __queryKey?: string; +} diff --git a/src/react/hooks/useSuspenseQuery.ts b/src/react/hooks/useSuspenseQuery.ts index daabb7e3eeb..fd1df0129f2 100644 --- a/src/react/hooks/useSuspenseQuery.ts +++ b/src/react/hooks/useSuspenseQuery.ts @@ -25,7 +25,7 @@ import { getSuspenseCache } from "../cache/index.js"; import { canonicalStringify } from "../../cache/index.js"; import { skipToken } from "./constants.js"; import type { SkipToken } from "./constants.js"; -import type { CacheKey } from "../cache/types.js"; +import type { CacheKey, QueryKey } from "../cache/types.js"; export interface UseSuspenseQueryResult< TData = unknown, @@ -197,7 +197,7 @@ export function useSuspenseQuery< ); let [current, setPromise] = React.useState< - [CacheKey, Promise>] + [QueryKey, Promise>] >([queryRef.key, queryRef.promise]); if (current[0] !== queryRef.key) {