@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
112 lines • 3.22 kB
TypeScript
import type { ApolloClient, OperationVariables } from "@apollo/client";
import React from "react";
import type { PreloadQuery } from "./PreloadQuery.js";
/**
* > This export is only available in React Server Components
*
* Ensures that you can always access the same instance of ApolloClient
* during RSC for an ongoing request, while always returning
* a new instance for different requests.
*
* @example
* ```ts
* export const { getClient, query, PreloadQuery } = registerApolloClient(() => {
* return new ApolloClient({
* cache: new InMemoryCache(),
* link: new HttpLink({
* uri: "http://example.com/api/graphql",
* }),
* });
* });
* ```
*
* @public
*/
export declare function registerApolloClient<ApolloClientOrPromise extends Promise<ApolloClient> | ApolloClient>(makeClient: () => ApolloClientOrPromise): {
getClient: () => ApolloClientOrPromise;
query: Awaited<ApolloClientOrPromise>["query"];
/**
* Preloads data in React Server Components to be hydrated
* in Client Components.
*
* ### Example with `queryRef`
* `ClientChild` would call `useReadQuery` with the `queryRef`, the `Suspense` boundary is optional:
* ```jsx
* <PreloadQuery
* query={QUERY}
* variables={{
* foo: 1
* }}
* >
* {(queryRef) => (
* <Suspense fallback={<>loading</>}>
* <ClientChild queryRef={queryRef} />
* </Suspense>
* )}
* </PreloadQuery>
* ```
*
* ### Example for `useSuspenseQuery`
* `ClientChild` would call the same query with `useSuspenseQuery`, the `Suspense` boundary is optional:
* ```jsx
* <PreloadQuery
* query={QUERY}
* variables={{
* foo: 1
* }}
* >
* <Suspense fallback={<>loading</>}>
* <ClientChild />
* </Suspense>
* </PreloadQuery>
* ```
*/
PreloadQuery: PreloadQueryComponent;
};
/**
* @deprecated use `PreloadQuery.Props` instead
* @public
*/
export type PreloadQueryProps<TData, TVariables extends OperationVariables> = PreloadQuery.Props<TData, TVariables>;
/**
* Preloads data in React Server Components to be hydrated
* in Client Components.
*
* ### Example with `queryRef`
* `ClientChild` would call `useReadQuery` with the `queryRef`, the `Suspense` boundary is optional:
* ```jsx
* <PreloadQuery
* query={QUERY}
* variables={{
* foo: 1
* }}
* >
* {(queryRef) => (
* <Suspense fallback={<>loading</>}>
* <ClientChild queryRef={queryRef} />
* </Suspense>
* )}
* </PreloadQuery>
* ```
*
* ### Example for `useSuspenseQuery`
* `ClientChild` would call the same query with `useSuspenseQuery`, the `Suspense` boundary is optional:
* ```jsx
* <PreloadQuery
* query={QUERY}
* variables={{
* foo: 1
* }}
* >
* <Suspense fallback={<>loading</>}>
* <ClientChild />
* </Suspense>
* </PreloadQuery>
* ```
*
* @public
*/
export interface PreloadQueryComponent {
<TData, TVariables extends OperationVariables>(props: PreloadQuery.Props<TData, TVariables>): React.ReactElement;
}
//# sourceMappingURL=registerApolloClient.d.ts.map