Skip to content

Commit 47ad806

Browse files
create branded QueryRef type without exposed properties (#11824)
* create branded `QueryReferenceBase` type * update some test types * changeset * split up into new hierarchy starting from QueryRef type * add export * add some type assignability tests * update doc references * toPromise return type * adjust changeset * stabilize flaky test * Update .changeset/late-planets-argue.md Co-authored-by: Jerel Miller <[email protected]> * types in tests * adjust notes * fix integration test TS --------- Co-authored-by: Jerel Miller <[email protected]>
1 parent 857f100 commit 47ad806

33 files changed

+666
-620
lines changed

.api-reports/api-report-react.md

Lines changed: 29 additions & 135 deletions
Large diffs are not rendered by default.

.api-reports/api-report-react_hooks.md

Lines changed: 17 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,6 @@ type FetchMoreFunction<TData, TVariables extends OperationVariables> = (fetchMor
725725
}) => TData;
726726
}) => Promise<ApolloQueryResult<TData>>;
727727

728-
// @public (undocumented)
729-
type FetchMoreOptions<TData> = Parameters<ObservableQuery<TData>["fetchMore"]>[0];
730-
731728
// @public (undocumented)
732729
interface FetchMoreQueryOptions<TVariables, TData = any> {
733730
// (undocumented)
@@ -768,14 +765,6 @@ interface FragmentMap {
768765
// @public (undocumented)
769766
type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean;
770767

771-
// @public (undocumented)
772-
interface FulfilledPromise<TValue> extends Promise<TValue> {
773-
// (undocumented)
774-
status: "fulfilled";
775-
// (undocumented)
776-
value: TValue;
777-
}
778-
779768
// @internal
780769
const getApolloCacheMemoryInternals: (() => {
781770
cache: {
@@ -860,58 +849,6 @@ interface IncrementalPayload<TData, TExtensions> {
860849
path: Path;
861850
}
862851

863-
// @public (undocumented)
864-
class InternalQueryReference<TData = unknown> {
865-
// Warning: (ae-forgotten-export) The symbol "InternalQueryReferenceOptions" needs to be exported by the entry point index.d.ts
866-
constructor(observable: ObservableQuery<TData, any>, options: InternalQueryReferenceOptions);
867-
// (undocumented)
868-
applyOptions(watchQueryOptions: ObservedOptions): QueryRefPromise<TData>;
869-
// Warning: (ae-forgotten-export) The symbol "ObservedOptions" needs to be exported by the entry point index.d.ts
870-
//
871-
// (undocumented)
872-
didChangeOptions(watchQueryOptions: ObservedOptions): boolean;
873-
// (undocumented)
874-
get disposed(): boolean;
875-
// Warning: (ae-forgotten-export) The symbol "FetchMoreOptions" needs to be exported by the entry point index.d.ts
876-
//
877-
// (undocumented)
878-
fetchMore(options: FetchMoreOptions<TData>): Promise<ApolloQueryResult<TData>>;
879-
// Warning: (ae-forgotten-export) The symbol "QueryKey" needs to be exported by the entry point index.d.ts
880-
//
881-
// (undocumented)
882-
readonly key: QueryKey;
883-
// Warning: (ae-forgotten-export) The symbol "Listener" needs to be exported by the entry point index.d.ts
884-
//
885-
// (undocumented)
886-
listen(listener: Listener<TData>): () => void;
887-
// (undocumented)
888-
readonly observable: ObservableQuery<TData>;
889-
// Warning: (ae-forgotten-export) The symbol "QueryRefPromise" needs to be exported by the entry point index.d.ts
890-
//
891-
// (undocumented)
892-
promise: QueryRefPromise<TData>;
893-
// (undocumented)
894-
refetch(variables: OperationVariables | undefined): Promise<ApolloQueryResult<TData>>;
895-
// (undocumented)
896-
reinitialize(): void;
897-
// (undocumented)
898-
result: ApolloQueryResult<TData>;
899-
// (undocumented)
900-
retain(): () => void;
901-
// (undocumented)
902-
softRetain(): () => void;
903-
// (undocumented)
904-
get watchQueryOptions(): WatchQueryOptions<OperationVariables, TData>;
905-
}
906-
907-
// @public (undocumented)
908-
interface InternalQueryReferenceOptions {
909-
// (undocumented)
910-
autoDisposeTimeoutMs?: number;
911-
// (undocumented)
912-
onDispose?: () => void;
913-
}
914-
915852
// Warning: (ae-forgotten-export) The symbol "InternalRefetchQueryDescriptor" needs to be exported by the entry point index.d.ts
916853
// Warning: (ae-forgotten-export) The symbol "RefetchQueriesIncludeShorthand" needs to be exported by the entry point index.d.ts
917854
//
@@ -991,9 +928,6 @@ execute: LazyQueryExecFunction<TData, TVariables>,
991928
result: QueryResult<TData, TVariables>
992929
];
993930

994-
// @public (undocumented)
995-
type Listener<TData> = (promise: QueryRefPromise<TData>) => void;
996-
997931
// @public (undocumented)
998932
type LoadableQueryHookFetchPolicy = Extract<WatchQueryFetchPolicy, "cache-first" | "network-only" | "no-cache" | "cache-and-network">;
999933

@@ -1323,14 +1257,6 @@ interface ObservableQueryFields<TData, TVariables extends OperationVariables> {
13231257
variables: TVariables | undefined;
13241258
}
13251259

1326-
// @public (undocumented)
1327-
const OBSERVED_CHANGED_OPTIONS: readonly ["canonizeResults", "context", "errorPolicy", "fetchPolicy", "refetchWritePolicy", "returnPartialData"];
1328-
1329-
// Warning: (ae-forgotten-export) The symbol "OBSERVED_CHANGED_OPTIONS" needs to be exported by the entry point index.d.ts
1330-
//
1331-
// @public (undocumented)
1332-
type ObservedOptions = Pick<WatchQueryOptions, (typeof OBSERVED_CHANGED_OPTIONS)[number]>;
1333-
13341260
// @public (undocumented)
13351261
interface OnDataOptions<TData = any> {
13361262
// (undocumented)
@@ -1382,27 +1308,11 @@ type OperationVariables = Record<string, any>;
13821308
// @public (undocumented)
13831309
type Path = ReadonlyArray<string | number>;
13841310

1385-
// @public (undocumented)
1386-
interface PendingPromise<TValue> extends Promise<TValue> {
1387-
// (undocumented)
1388-
status: "pending";
1389-
}
1390-
13911311
// @public (undocumented)
13921312
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
13931313

13941314
// @public (undocumented)
1395-
const PROMISE_SYMBOL: unique symbol;
1396-
1397-
// Warning: (ae-forgotten-export) The symbol "PendingPromise" needs to be exported by the entry point index.d.ts
1398-
// Warning: (ae-forgotten-export) The symbol "FulfilledPromise" needs to be exported by the entry point index.d.ts
1399-
// Warning: (ae-forgotten-export) The symbol "RejectedPromise" needs to be exported by the entry point index.d.ts
1400-
//
1401-
// @public (undocumented)
1402-
type PromiseWithState<TValue> = PendingPromise<TValue> | FulfilledPromise<TValue> | RejectedPromise<TValue>;
1403-
1404-
// @public (undocumented)
1405-
const QUERY_REFERENCE_SYMBOL: unique symbol;
1315+
const QUERY_REF_BRAND: unique symbol;
14061316

14071317
// @public (undocumented)
14081318
interface QueryFunctionOptions<TData = any, TVariables extends OperationVariables = OperationVariables> extends BaseQueryOptions<TVariables, TData> {
@@ -1478,12 +1388,6 @@ class QueryInfo {
14781388
variables?: Record<string, any>;
14791389
}
14801390

1481-
// @public (undocumented)
1482-
interface QueryKey {
1483-
// (undocumented)
1484-
__queryKey?: string;
1485-
}
1486-
14871391
// @public (undocumented)
14881392
type QueryListener = (queryInfo: QueryInfo) => void;
14891393

@@ -1628,21 +1532,11 @@ interface QueryOptions<TVariables = OperationVariables, TData = any> {
16281532
}
16291533

16301534
// @public
1631-
interface QueryReference<TData = unknown, TVariables = unknown> {
1535+
interface QueryRef<TData = unknown, TVariables = unknown> {
16321536
// @internal (undocumented)
1633-
[PROMISE_SYMBOL]: QueryRefPromise<TData>;
1634-
// Warning: (ae-forgotten-export) The symbol "InternalQueryReference" needs to be exported by the entry point index.d.ts
1635-
//
1636-
// @internal (undocumented)
1637-
readonly [QUERY_REFERENCE_SYMBOL]: InternalQueryReference<TData>;
1638-
toPromise(): Promise<QueryReference<TData, TVariables>>;
1537+
[QUERY_REF_BRAND]?(variables: TVariables): TData;
16391538
}
16401539

1641-
// Warning: (ae-forgotten-export) The symbol "PromiseWithState" needs to be exported by the entry point index.d.ts
1642-
//
1643-
// @public (undocumented)
1644-
type QueryRefPromise<TData> = PromiseWithState<ApolloQueryResult<TData>>;
1645-
16461540
// Warning: (ae-forgotten-export) The symbol "ObservableQueryFields" needs to be exported by the entry point index.d.ts
16471541
//
16481542
// @public (undocumented)
@@ -1744,14 +1638,6 @@ type RefetchQueryDescriptor = string | DocumentNode;
17441638
// @public (undocumented)
17451639
type RefetchWritePolicy = "merge" | "overwrite";
17461640

1747-
// @public (undocumented)
1748-
interface RejectedPromise<TValue> extends Promise<TValue> {
1749-
// (undocumented)
1750-
reason: unknown;
1751-
// (undocumented)
1752-
status: "rejected";
1753-
}
1754-
17551641
// @public (undocumented)
17561642
type RequestHandler = (operation: Operation, forward: NextLink) => Observable<FetchResult> | null;
17571643

@@ -1955,11 +1841,11 @@ interface UriFunction {
19551841
export function useApolloClient(override?: ApolloClient<object>): ApolloClient<object>;
19561842

19571843
// Warning: (ae-forgotten-export) The symbol "BackgroundQueryHookOptionsNoInfer" needs to be exported by the entry point index.d.ts
1958-
// Warning: (ae-forgotten-export) The symbol "QueryReference" needs to be exported by the entry point index.d.ts
1844+
// Warning: (ae-forgotten-export) The symbol "QueryRef" needs to be exported by the entry point index.d.ts
19591845
//
19601846
// @public (undocumented)
19611847
export function useBackgroundQuery<TData, TVariables extends OperationVariables, TOptions extends Omit<BackgroundQueryHookOptions<TData>, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions): [
1962-
(QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables> | (TOptions["skip"] extends boolean ? undefined : never)),
1848+
(QueryRef<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables> | (TOptions["skip"] extends boolean ? undefined : never)),
19631849
UseBackgroundQueryResult<TData, TVariables>
19641850
];
19651851

@@ -1968,15 +1854,15 @@ export function useBackgroundQuery<TData = unknown, TVariables extends Operation
19681854
returnPartialData: true;
19691855
errorPolicy: "ignore" | "all";
19701856
}): [
1971-
QueryReference<DeepPartial<TData> | undefined, TVariables>,
1857+
QueryRef<DeepPartial<TData> | undefined, TVariables>,
19721858
UseBackgroundQueryResult<TData, TVariables>
19731859
];
19741860

19751861
// @public (undocumented)
19761862
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
19771863
errorPolicy: "ignore" | "all";
19781864
}): [
1979-
QueryReference<TData | undefined, TVariables>,
1865+
QueryRef<TData | undefined, TVariables>,
19801866
UseBackgroundQueryResult<TData, TVariables>
19811867
];
19821868

@@ -1985,31 +1871,28 @@ export function useBackgroundQuery<TData = unknown, TVariables extends Operation
19851871
skip: boolean;
19861872
returnPartialData: true;
19871873
}): [
1988-
QueryReference<DeepPartial<TData>, TVariables> | undefined,
1874+
QueryRef<DeepPartial<TData>, TVariables> | undefined,
19891875
UseBackgroundQueryResult<TData, TVariables>
19901876
];
19911877

19921878
// @public (undocumented)
19931879
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
19941880
returnPartialData: true;
19951881
}): [
1996-
QueryReference<DeepPartial<TData>, TVariables>,
1882+
QueryRef<DeepPartial<TData>, TVariables>,
19971883
UseBackgroundQueryResult<TData, TVariables>
19981884
];
19991885

20001886
// @public (undocumented)
20011887
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
20021888
skip: boolean;
20031889
}): [
2004-
QueryReference<TData, TVariables> | undefined,
1890+
QueryRef<TData, TVariables> | undefined,
20051891
UseBackgroundQueryResult<TData, TVariables>
20061892
];
20071893

20081894
// @public (undocumented)
2009-
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
2010-
QueryReference<TData, TVariables>,
2011-
UseBackgroundQueryResult<TData, TVariables>
2012-
];
1895+
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [QueryRef<TData, TVariables>, UseBackgroundQueryResult<TData, TVariables>];
20131896

20141897
// @public (undocumented)
20151898
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): [undefined, UseBackgroundQueryResult<TData, TVariables>];
@@ -2018,13 +1901,13 @@ export function useBackgroundQuery<TData = unknown, TVariables extends Operation
20181901
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
20191902
returnPartialData: true;
20201903
})): [
2021-
QueryReference<DeepPartial<TData>, TVariables> | undefined,
1904+
QueryRef<DeepPartial<TData>, TVariables> | undefined,
20221905
UseBackgroundQueryResult<TData, TVariables>
20231906
];
20241907

20251908
// @public (undocumented)
20261909
export function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
2027-
QueryReference<TData, TVariables> | undefined,
1910+
QueryRef<TData, TVariables> | undefined,
20281911
UseBackgroundQueryResult<TData, TVariables>
20291912
];
20301913

@@ -2089,7 +1972,7 @@ export function useLoadableQuery<TData = unknown, TVariables extends OperationVa
20891972
// @public (undocumented)
20901973
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
20911974
loadQuery: LoadQueryFunction<TVariables>,
2092-
queryRef: QueryReference<TData, TVariables> | null,
1975+
queryRef: QueryRef<TData, TVariables> | null,
20931976
{
20941977
fetchMore: FetchMoreFunction<TData, TVariables>;
20951978
refetch: RefetchFunction<TData, TVariables>;
@@ -2107,7 +1990,7 @@ export function useMutation<TData = any, TVariables = OperationVariables, TConte
21071990
export function useQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<NoInfer_2<TData>, NoInfer_2<TVariables>>): QueryResult<TData, TVariables>;
21081991

21091992
// @public
2110-
export function useQueryRefHandlers<TData = unknown, TVariables extends OperationVariables = OperationVariables>(queryRef: QueryReference<TData, TVariables>): UseQueryRefHandlersResult<TData, TVariables>;
1993+
export function useQueryRefHandlers<TData = unknown, TVariables extends OperationVariables = OperationVariables>(queryRef: QueryRef<TData, TVariables>): UseQueryRefHandlersResult<TData, TVariables>;
21111994

21121995
// @public (undocumented)
21131996
export interface UseQueryRefHandlersResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
@@ -2121,7 +2004,7 @@ export interface UseQueryRefHandlersResult<TData = unknown, TVariables extends O
21212004
export function useReactiveVar<T>(rv: ReactiveVar<T>): T;
21222005

21232006
// @public (undocumented)
2124-
export function useReadQuery<TData>(queryRef: QueryReference<TData>): UseReadQueryResult<TData>;
2007+
export function useReadQuery<TData>(queryRef: QueryRef<TData>): UseReadQueryResult<TData>;
21252008

21262009
// @public (undocumented)
21272010
export interface UseReadQueryResult<TData = unknown> {
@@ -2248,7 +2131,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
22482131
// src/core/watchQueryOptions.ts:269:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
22492132
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
22502133
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
2251-
// src/react/hooks/useLoadableQuery.ts:106:1 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
2134+
// src/react/hooks/useLoadableQuery.ts:107:1 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
22522135

22532136
// (No @packageDocumentation comment for this package)
22542137

0 commit comments

Comments
 (0)