Skip to content

Commit

Permalink
change key to empty object
Browse files Browse the repository at this point in the history
we only care about identity, not about contents
  • Loading branch information
phryneas committed Nov 16, 2023
1 parent 532505a commit 50c2149
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/react/cache/QueryReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData> = (promise: Promise<ApolloQueryResult<TData>>) => void;
Expand Down Expand Up @@ -65,10 +65,10 @@ type ObservedOptions = Pick<

export class InternalQueryReference<TData = unknown> {
public result: ApolloQueryResult<TData>;
public readonly key: CacheKey;
public readonly key: QueryKey = {};
public readonly observable: ObservableQuery<TData>;

public promiseCache?: Map<CacheKey, Promise<ApolloQueryResult<TData>>>;
public promiseCache?: Map<QueryKey, Promise<ApolloQueryResult<TData>>>;
public promise: Promise<ApolloQueryResult<TData>>;

private subscription: ObservableSubscription;
Expand All @@ -92,7 +92,6 @@ export class InternalQueryReference<TData = unknown> {
// 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;
Expand Down
4 changes: 4 additions & 0 deletions src/react/cache/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export type CacheKey = [
stringifiedVariables: string,
...queryKey: any[],
];

export interface QueryKey {
__queryKey?: string;
}
4 changes: 2 additions & 2 deletions src/react/hooks/useSuspenseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -197,7 +197,7 @@ export function useSuspenseQuery<
);

let [current, setPromise] = React.useState<
[CacheKey, Promise<ApolloQueryResult<any>>]
[QueryKey, Promise<ApolloQueryResult<any>>]
>([queryRef.key, queryRef.promise]);

if (current[0] !== queryRef.key) {
Expand Down

0 comments on commit 50c2149

Please sign in to comment.