From 8f3e58088fa580aabbf23bef9c35db9e1038cc9f Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 15 Apr 2024 16:52:54 +0200 Subject: [PATCH] tweaks --- integration-test/nextjs/src/app/rsc/client.ts | 2 +- .../src/PreloadQuery.tsx | 5 ++- .../src/registerApolloClient.tsx | 40 +++++++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/integration-test/nextjs/src/app/rsc/client.ts b/integration-test/nextjs/src/app/rsc/client.ts index 8a2a0f6d..34ea96df 100644 --- a/integration-test/nextjs/src/app/rsc/client.ts +++ b/integration-test/nextjs/src/app/rsc/client.ts @@ -1,4 +1,4 @@ -import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client"; +import { ApolloClient, InMemoryCache } from "@apollo/client"; import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc"; import { loadErrorMessages, loadDevMessages } from "@apollo/client/dev"; diff --git a/packages/client-react-streaming/src/PreloadQuery.tsx b/packages/client-react-streaming/src/PreloadQuery.tsx index 025608fa..6c38f89c 100644 --- a/packages/client-react-streaming/src/PreloadQuery.tsx +++ b/packages/client-react-streaming/src/PreloadQuery.tsx @@ -4,6 +4,7 @@ import type { OperationVariables, QueryOptions, QueryReference, + FetchPolicy, } from "@apollo/client"; import type { ReactNode } from "react"; import React, { useId } from "react"; @@ -13,7 +14,8 @@ import { createTransportedQueryRef } from "./transportedQueryRef.js"; export type RestrictedPreloadOptions = { fetchPolicy?: "cache-first"; returnPartialData?: false; - // TODO: what else goes in here? + nextFetchPolicy?: FetchPolicy | undefined; + pollInterval?: undefined; }; export type PreloadQueryOptions = QueryOptions< @@ -39,6 +41,7 @@ export function PreloadQuery({ ...options, fetchPolicy: "cache-first" as const, returnPartialData: false, + pollInterval: undefined, } satisfies RestrictedPreloadOptions; const transportedOptions = sanitizeForTransport( diff --git a/packages/client-react-streaming/src/registerApolloClient.tsx b/packages/client-react-streaming/src/registerApolloClient.tsx index 5cc0fc0b..9565b8ad 100644 --- a/packages/client-react-streaming/src/registerApolloClient.tsx +++ b/packages/client-react-streaming/src/registerApolloClient.tsx @@ -44,6 +44,42 @@ export function registerApolloClient< ): { getClient: () => AC; query: Awaited["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: + * ```js + * + * {(queryRef) => ( + * loading}> + * + * + * )} + * + * ``` + * + * ### Example for `useSuspenseQuery` + * `ClientChild` would call the same query with `useSuspenseQuery`, the `Suspense` boundary is optional: + * ```js + * + * loading}> + * + * + * + * ``` + */ PreloadQuery: PreloadQueryComponent; } { const getClient = makeGetClient(makeClient); @@ -121,10 +157,6 @@ interface PreloadQueryProps { } interface PreloadQueryComponent { - /** - * Preloads data in React Server Components to be hydrated - * in Client Components. - */ ( props: PreloadQueryProps ): React.ReactNode;