@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
58 lines • 2.11 kB
TypeScript
import { ApolloLink } from "@apollo/client";
/**
* @internal
*/
export type ReadableStreamLinkEvent = {
type: "next";
value: ApolloLink.Result;
} | {
type: "completed";
} | {
type: "error";
};
/**
* Called when the link is hit, before the request is forwarded.
*
* Should return the controller for the readable stream.
*
* This is useful because when starting a query, it's not always
* clear if the query will hit the network or will be served from
* cache, deduplicated etc.
* This allows to inject the "start event" into the stream only
* when we know that more chunks will actually follow.
*/
type OnLinkHitFunction = () => ReadableStreamDefaultController<ReadableStreamLinkEvent>;
interface InternalContext {
[teeToReadableStreamKey]?: OnLinkHitFunction;
[readFromReadableStreamKey]?: ReadableStream<ReadableStreamLinkEvent>;
}
declare const teeToReadableStreamKey: unique symbol;
declare const readFromReadableStreamKey: unique symbol;
/**
* Apply to a context that will be passed to a link chain containing `TeeToReadableStreamLink`.
* @public
*/
export declare function teeToReadableStream<T extends Record<string, any>>(onLinkHit: OnLinkHitFunction, context: T): T & InternalContext;
/**
* Apply to a context that will be passed to a link chain containing `ReadFromReadableStreamLink`.
* @public
*/
export declare function readFromReadableStream<T extends Record<string, any>>(readableStream: ReadableStream<ReadableStreamLinkEvent>, context: T): T & InternalContext;
/**
* A link that allows the request to be cloned into a readable stream, e.g. for
* transport of multipart responses from RSC or a server loader to the browser.
* @public
*/
export declare class TeeToReadableStreamLink extends ApolloLink {
constructor();
}
/**
* A link that allows the response to be read from a readable stream, e.g. for
* hydration of a multipart response from RSC or a server loader in the browser.
* @public
*/
export declare class ReadFromReadableStreamLink extends ApolloLink {
constructor();
}
export {};
//# sourceMappingURL=ReadableStreamLink.d.ts.map