Skip to content

Commit

Permalink
Feature: useSuspenseFragment (#12066)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller authored Feb 4, 2025
1 parent e189596 commit c01da5d
Show file tree
Hide file tree
Showing 15 changed files with 2,498 additions and 11 deletions.
42 changes: 40 additions & 2 deletions .api-reports/api-report-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,11 @@ TData
};
} : never : never;

// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type From<TData> = StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;

// @internal
const getApolloCacheMemoryInternals: (() => {
cache: {
Expand Down Expand Up @@ -2317,8 +2322,6 @@ export function useFragment<TData = any, TVars = OperationVariables>(options: Us
// @public (undocumented)
export interface UseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
//
// (undocumented)
from: StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;
// (undocumented)
Expand Down Expand Up @@ -2413,6 +2416,40 @@ export function useSubscription<TData = any, TVariables extends OperationVariabl
variables?: TVariables | undefined;
};

// Warning: (ae-forgotten-export) The symbol "UseSuspenseFragmentOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: NonNullable<From<TData>>;
}): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: null;
}): UseSuspenseFragmentResult<null>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: From<TData>;
}): UseSuspenseFragmentResult<TData | null>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables>): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
interface UseSuspenseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// (undocumented)
from: From<TData>;
// (undocumented)
optimistic?: boolean;
}

// @public (undocumented)
export type UseSuspenseFragmentResult<TData> = {
data: MaybeMasked<TData>;
};

// @public (undocumented)
export function useSuspenseQuery<TData, TVariables extends OperationVariables, TOptions extends Omit<SuspenseQueryHookOptions<TData>, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SuspenseQueryHookOptions<NoInfer_2<TData>, NoInfer_2<TVariables>> & TOptions): UseSuspenseQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? TOptions["skip"] extends boolean ? DeepPartial<TData> | undefined : DeepPartial<TData> : TOptions["skip"] extends boolean ? TData | undefined : TData, TVariables>;

Expand Down Expand Up @@ -2531,6 +2568,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:120:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useSuspenseFragment.ts:60:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
42 changes: 40 additions & 2 deletions .api-reports/api-report-react_hooks.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ TData
};
} : never : never;

// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type From<TData> = StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;

// @internal
const getApolloCacheMemoryInternals: (() => {
cache: {
Expand Down Expand Up @@ -2141,8 +2146,6 @@ export function useFragment<TData = any, TVars = OperationVariables>(options: Us
// @public (undocumented)
export interface UseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
//
// (undocumented)
from: StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;
// (undocumented)
Expand Down Expand Up @@ -2246,6 +2249,40 @@ export function useSubscription<TData = any, TVariables extends OperationVariabl
variables?: TVariables | undefined;
};

// Warning: (ae-forgotten-export) The symbol "UseSuspenseFragmentOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: NonNullable<From<TData>>;
}): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: null;
}): UseSuspenseFragmentResult<null>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: From<TData>;
}): UseSuspenseFragmentResult<TData | null>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables>): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
interface UseSuspenseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// (undocumented)
from: From<TData>;
// (undocumented)
optimistic?: boolean;
}

// @public (undocumented)
export type UseSuspenseFragmentResult<TData> = {
data: MaybeMasked<TData>;
};

// Warning: (ae-forgotten-export) The symbol "SuspenseQueryHookOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
Expand Down Expand Up @@ -2355,6 +2392,7 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:120:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useSuspenseFragment.ts:60:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
109 changes: 105 additions & 4 deletions .api-reports/api-report-react_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,19 @@ interface FieldSpecifier {
variables?: Record<string, any>;
}

// @public (undocumented)
type FragmentCacheKey = [
cacheId: string,
fragment: DocumentNode,
stringifiedVariables: string
];

// @public (undocumented)
interface FragmentKey {
// (undocumented)
__fragmentKey?: string;
}

// @public
interface FragmentMap {
// (undocumented)
Expand All @@ -816,6 +829,43 @@ interface FragmentMap {
// @public (undocumented)
type FragmentMatcher = (rootValue: any, typeCondition: string, context: any) => boolean;

// @public (undocumented)
class FragmentReference<TData = unknown, TVariables = Record<string, unknown>> {
// Warning: (ae-forgotten-export) The symbol "FragmentReferenceOptions" needs to be exported by the entry point index.d.ts
constructor(client: ApolloClient<any>, watchFragmentOptions: WatchFragmentOptions<TData, TVariables> & {
from: string;
}, options: FragmentReferenceOptions);
// Warning: (ae-forgotten-export) The symbol "FragmentKey" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly key: FragmentKey;
// Warning: (ae-forgotten-export) The symbol "Listener_2" needs to be exported by the entry point index.d.ts
//
// (undocumented)
listen(listener: Listener_2<MaybeMasked<TData>>): () => void;
// (undocumented)
readonly observable: Observable<WatchFragmentResult<TData>>;
// Warning: (ae-forgotten-export) The symbol "FragmentRefPromise" needs to be exported by the entry point index.d.ts
//
// (undocumented)
promise: FragmentRefPromise<MaybeMasked<TData>>;
// (undocumented)
retain(): () => void;
}

// @public (undocumented)
interface FragmentReferenceOptions {
// (undocumented)
autoDisposeTimeoutMs?: number;
// (undocumented)
onDispose?: () => void;
}

// Warning: (ae-forgotten-export) The symbol "PromiseWithState" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type FragmentRefPromise<TData> = PromiseWithState<TData>;

// @public (undocumented)
type FragmentType<TData> = [
TData
Expand All @@ -827,6 +877,11 @@ TData
};
} : never : never;

// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type From<TData> = StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;

// @public (undocumented)
interface FulfilledPromise<TValue> extends Promise<TValue> {
// (undocumented)
Expand Down Expand Up @@ -1036,6 +1091,9 @@ type IsStrictlyAny<T> = UnionToIntersection<UnionForAny<T>> extends never ? true
// @public (undocumented)
type Listener<TData> = (promise: QueryRefPromise<TData>) => void;

// @public (undocumented)
type Listener_2<TData> = (promise: FragmentRefPromise<TData>) => void;

// @public (undocumented)
class LocalState<TCacheShape> {
// Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1766,8 +1824,6 @@ export interface QueryReference<TData = unknown, TVariables = unknown> extends Q
toPromise?: unknown;
}

// Warning: (ae-forgotten-export) The symbol "PromiseWithState" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
type QueryRefPromise<TData> = PromiseWithState<ApolloQueryResult<MaybeMasked<TData>>>;

Expand Down Expand Up @@ -1999,6 +2055,13 @@ class SuspenseCache {
constructor(options?: SuspenseCacheOptions);
// (undocumented)
add(cacheKey: CacheKey, queryRef: InternalQueryReference<unknown>): void;
// Warning: (ae-forgotten-export) The symbol "FragmentCacheKey" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "FragmentReference" needs to be exported by the entry point index.d.ts
//
// (undocumented)
getFragmentRef<TData, TVariables>(cacheKey: FragmentCacheKey, client: ApolloClient<any>, options: WatchFragmentOptions<TData, TVariables> & {
from: string;
}): FragmentReference<TData, TVariables>;
// (undocumented)
getQueryRef<TData = any>(cacheKey: CacheKey, createObservable: () => ObservableQuery<TData>): InternalQueryReference<TData>;
}
Expand Down Expand Up @@ -2203,8 +2266,6 @@ function useFragment<TData = any, TVars = OperationVariables>(options: UseFragme
// @public (undocumented)
interface UseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// Warning: (ae-forgotten-export) The symbol "FragmentType" needs to be exported by the entry point index.d.ts
//
// (undocumented)
from: StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;
// (undocumented)
Expand Down Expand Up @@ -2251,6 +2312,41 @@ interface UseReadQueryResult<TData = unknown> {
networkStatus: NetworkStatus;
}

// Warning: (ae-forgotten-export) The symbol "UseSuspenseFragmentOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UseSuspenseFragmentResult" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: NonNullable<From<TData>>;
}): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: null;
}): UseSuspenseFragmentResult<null>;

// @public (undocumented)
function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: From<TData>;
}): UseSuspenseFragmentResult<TData | null>;

// @public (undocumented)
function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables>): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
interface UseSuspenseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// (undocumented)
from: From<TData>;
// (undocumented)
optimistic?: boolean;
}

// @public (undocumented)
type UseSuspenseFragmentResult<TData> = {
data: MaybeMasked<TData>;
};

// Warning: (ae-forgotten-export) The symbol "SuspenseQueryHookOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UseSuspenseQueryResult" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -2378,6 +2474,10 @@ interface WrappableHooks {
//
// (undocumented)
useReadQuery: typeof useReadQuery;
// Warning: (ae-forgotten-export) The symbol "useSuspenseFragment" needs to be exported by the entry point index.d.ts
//
// (undocumented)
useSuspenseFragment: typeof useSuspenseFragment;
// Warning: (ae-forgotten-export) The symbol "useSuspenseQuery" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -2416,6 +2516,7 @@ export function wrapQueryRef<TData, TVariables extends OperationVariables>(inter
// src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useSuspenseFragment.ts:60:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts
// src/react/query-preloader/createQueryPreloader.ts:145:3 - (ae-forgotten-export) The symbol "PreloadQueryFetchPolicy" needs to be exported by the entry point index.d.ts
// src/react/query-preloader/createQueryPreloader.ts:167:5 - (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts

Expand Down
38 changes: 38 additions & 0 deletions .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,9 @@ TData
};
} : never : never;

// @public (undocumented)
type From<TData> = StoreObject | Reference | FragmentType<NoInfer_2<TData>> | string | null;

// @public (undocumented)
export const from: typeof ApolloLink.from;

Expand Down Expand Up @@ -3084,6 +3087,40 @@ export function useSubscription<TData = any, TVariables extends OperationVariabl
variables?: TVariables | undefined;
};

// Warning: (ae-forgotten-export) The symbol "UseSuspenseFragmentOptions" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: NonNullable<From<TData>>;
}): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: null;
}): UseSuspenseFragmentResult<null>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables> & {
from: From<TData>;
}): UseSuspenseFragmentResult<TData | null>;

// @public (undocumented)
export function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: UseSuspenseFragmentOptions<TData, TVariables>): UseSuspenseFragmentResult<TData>;

// @public (undocumented)
interface UseSuspenseFragmentOptions<TData, TVars> extends Omit<Cache_2.DiffOptions<NoInfer_2<TData>, NoInfer_2<TVars>>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache_2.ReadFragmentOptions<TData, TVars>, "id" | "variables" | "returnPartialData"> {
client?: ApolloClient<any>;
// (undocumented)
from: From<TData>;
// (undocumented)
optimistic?: boolean;
}

// @public (undocumented)
export type UseSuspenseFragmentResult<TData> = {
data: MaybeMasked<TData>;
};

// @public (undocumented)
export function useSuspenseQuery<TData, TVariables extends OperationVariables, TOptions extends Omit<SuspenseQueryHookOptions<TData>, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SuspenseQueryHookOptions<NoInfer_2<TData>, NoInfer_2<TVariables>> & TOptions): UseSuspenseQueryResult<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? TOptions["skip"] extends boolean ? DeepPartial<TData> | undefined : DeepPartial<TData> : TOptions["skip"] extends boolean ? TData | undefined : TData, TVariables>;

Expand Down Expand Up @@ -3230,6 +3267,7 @@ interface WriteContext extends ReadMergeModifyContext {
// src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:120:9 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useSuspenseFragment.ts:60:5 - (ae-forgotten-export) The symbol "From" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
Loading

0 comments on commit c01da5d

Please sign in to comment.