UNPKG

@apollo/client-react-streaming

Version:

This package provides building blocks to create framework-level integration of Apollo Client with React's streaming SSR. See the [@apollo/client-integration-nextjs](https://github.com/apollographql/apollo-client-integrations/tree/main/packages/nextjs) pac

73 lines 4.3 kB
import { wrapQueryRef } from "@apollo/client/react/internal"; import type { ReadableStreamLinkEvent } from "./ReadableStreamLink.js"; import type { QueryRef } from "@apollo/client/react"; import type { DocumentNode, ApolloClient, OperationVariables, TypedDocumentNode } from "@apollo/client"; import { type TransportedOptions } from "./DataTransportAbstraction/transportedOptions.js"; import { type JsonString } from "@apollo/client-react-streaming/stream-utils"; type RestrictedPreloadOptions = { fetchPolicy?: "network-only" | "cache-and-network" | "cache-first"; returnPartialData?: false; nextFetchPolicy?: undefined; pollInterval?: undefined; }; /** @public */ export type PreloadTransportedQueryOptions<TData, TVariables extends OperationVariables> = Omit<ApolloClient.QueryOptions<TData, TVariables>, "query"> & RestrictedPreloadOptions; type TransportedQueryRefOptions = TransportedOptions & RestrictedPreloadOptions; /** * A `TransportedQueryRef` is an opaque object accessible via renderProp within `PreloadQuery`. * * A child client component reading the `TransportedQueryRef` via useReadQuery will suspend until the promise resolves. * * @public */ export interface TransportedQueryRef<TData = unknown, TVariables extends OperationVariables = OperationVariables> extends QueryRef<TData, TVariables> { /** * Temporarily disabled - see https://github.com/apollographql/apollo-client-integrations/issues/332 * * Will now be be `undefined` both in React Server Components and Client Components until we can find a better resolution. */ toPromise?: undefined; /** @internal */ $__apollo_queryRef: { options: TransportedQueryRefOptions; stream: ReadableStream<JsonString<ReadableStreamLinkEvent>>; /** * A unique key for this query, to ensure it is only hydrated once, * even if it should get transported over the wire in a way that results * in multiple objects describing the same queryRef. * This key will be used to store the queryRef in the suspence cache. * * The chances of this happening should be slim (it is handled within * React thanks to https://github.com/facebook/react/pull/28996), but * as we use transported queryRefs with multiple frameworks with distinct * transport mechanisms, this seems like a safe option. */ queryKey: string; }; } /** @public */ export interface PreloadTransportedQueryFunction { <TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: PreloadTransportedQueryOptions<TData, NoInfer<TVariables>>): TransportedQueryRef<TData, TVariables>; } /** @internal */ export declare function getInjectableEventStream(): readonly [ReadableStreamDefaultController<ReadableStreamLinkEvent>, ReadableStream<ReadableStreamLinkEvent>]; /** @public */ export declare function createTransportedQueryPreloader(client: ApolloClient, { prepareForReuse, notTransportedOptionOverrides, }?: { /** * Set this to `true` to indicate that this `queryRef` will be reused within the same process with the same Apollo Client instance without being dehydrated and hydrated. * In that case, it will already be written to the suspense cache so it doesn't need to be hydrated by re-running the query with a fake network request. */ prepareForReuse?: boolean; /** * Overrides to the options that should happen only in the `preloader` call, but should not be transported/hydrated on the client. */ notTransportedOptionOverrides?: Partial<ApolloClient.WatchQueryOptions<any, any>>; }): PreloadTransportedQueryFunction; /** @public */ export declare function reviveTransportedQueryRef(queryRef: TransportedQueryRef, client: ApolloClient): asserts queryRef is TransportedQueryRef & ReturnType<typeof wrapQueryRef>; /** @public */ export declare function isTransportedQueryRef(queryRef: any): queryRef is TransportedQueryRef; /** @public */ export declare function useWrapTransportedQueryRef<TData>(queryRef: QueryRef<TData, any, "complete" | "streaming" | "empty" | "partial"> | TransportedQueryRef): QueryRef<TData>; export {}; //# sourceMappingURL=transportedQueryRef.d.ts.map