Skip to content

Commit

Permalink
move getClient into the promise chain
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Apr 15, 2024
1 parent f566049 commit 4e05fcb
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/client-react-streaming/src/PreloadQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ export type PreloadQueryOptions<TVariables, TData> = QueryOptions<
> &
RestrictedPreloadOptions;

export async function PreloadQuery<
TData,
TVariables extends OperationVariables,
>({
export function PreloadQuery<TData, TVariables extends OperationVariables>({
options,
getClient,
children,
Expand All @@ -38,10 +35,6 @@ export async function PreloadQuery<
queryRef: QueryReference<NoInfer<TData>, NoInfer<TVariables>>
) => ReactNode);
}) {
// is this legal?
// https://twitter.com/phry/status/1779833984299532439
const queryKey = useId();

const preloadOptions = {
...options,
fetchPolicy: "cache-first" as const,
Expand All @@ -52,10 +45,12 @@ export async function PreloadQuery<
serializeOptions(preloadOptions)
);

const resultPromise = (await getClient())
.query<TData, TVariables>(preloadOptions)
const resultPromise = Promise.resolve(getClient())
.then((client) => client.query<TData, TVariables>(preloadOptions))
.then(sanitizeForTransport);

const queryKey = useId();

return (
<SimulatePreloadedQuery<TData>
options={transportedOptions}
Expand Down

0 comments on commit 4e05fcb

Please sign in to comment.