Skip to content

Commit

Permalink
more fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Apr 11, 2024
1 parent 750eecb commit f9ea406
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
3 changes: 1 addition & 2 deletions integration-test/nextjs/src/app/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const resolvers = {
title: "The Apollo Socks",
},
],
env: (source, args, context, info) => {
console.log({ source, args, context, info });
env: (source, args, context) => {
return context && context.from === "network"
? "browser"
: "built_for_ssr" in entryPoint
Expand Down
26 changes: 0 additions & 26 deletions integration-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ __metadata:
version: 0.10.0
resolution: "@apollo/client-react-streaming@exec:./shared/build-client-react-streaming.cjs#./shared/build-client-react-streaming.cjs::hash=48b117&locator=%40integration-test%2Froot%40workspace%3A."
dependencies:
superjson: "npm:^1.12.2 || ^2.0.0"
ts-invariant: "npm:^0.10.3"
peerDependencies:
"@apollo/client": ^3.9.6
Expand Down Expand Up @@ -4010,15 +4009,6 @@ __metadata:
languageName: node
linkType: hard

"copy-anything@npm:^3.0.2":
version: 3.0.5
resolution: "copy-anything@npm:3.0.5"
dependencies:
is-what: "npm:^4.1.8"
checksum: 10/4c41385a94a1cff6352a954f9b1c05b6bb1b70713a2d31f4c7b188ae7187ce00ddcc9c09bd58d24cd35b67fc6dd84df5954c0be86ea10700ff74e677db3cb09c
languageName: node
linkType: hard

"core-js-compat@npm:^3.31.0, core-js-compat@npm:^3.34.0":
version: 3.36.0
resolution: "core-js-compat@npm:3.36.0"
Expand Down Expand Up @@ -5442,13 +5432,6 @@ __metadata:
languageName: node
linkType: hard

"is-what@npm:^4.1.8":
version: 4.1.16
resolution: "is-what@npm:4.1.16"
checksum: 10/f6400634bae77be6903365dc53817292e1c4d8db1b467515d0c842505b8388ee8e558326d5e6952cb2a9d74116eca2af0c6adb8aa7e9d5c845a130ce9328bf13
languageName: node
linkType: hard

"isarray@npm:^2.0.5":
version: 2.0.5
resolution: "isarray@npm:2.0.5"
Expand Down Expand Up @@ -7996,15 +7979,6 @@ __metadata:
languageName: node
linkType: hard

"superjson@npm:^1.12.2 || ^2.0.0":
version: 2.2.1
resolution: "superjson@npm:2.2.1"
dependencies:
copy-anything: "npm:^3.0.2"
checksum: 10/bb8743a87c97f7845e0c27af1af0731d3185b32099ebce2aee0e67ac9a6ae9a7c4b9edfca7e1fe48693a78b56d5922d1cd13ef80c2fa12b788d3fc0ca25afe47
languageName: node
linkType: hard

"supports-color@npm:^5.3.0":
version: 5.5.0
resolution: "supports-color@npm:5.5.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { QueryOptions } from "@apollo/client";
import {
getApolloContext,
createQueryPreloader,
gql,
} from "@apollo/client/index.js";
import { use } from "react";

Expand Down Expand Up @@ -54,7 +55,7 @@ function reviveTransportedQueryRef(queryRef: TransportedQueryRef) {
// TODO: discuss what to do with the fetchPolicy here
options.fetchPolicy = "cache-first";
queryRef.__transportedQueryRef = preloader(
query,
gql(query),
options as typeof options & { fetchPolicy: "cache-first" }
);
}
Expand Down
24 changes: 16 additions & 8 deletions packages/client-react-streaming/src/PreloadQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ReactNode } from "react";
import { SimulatePreloadedQuery } from "./index.cc.js";
import type {
ApolloClient,
FetchResult,
OperationVariables,
QueryOptions,
QueryReference,
Expand All @@ -23,13 +24,15 @@ export function PreloadQuery<TData, TVariables extends OperationVariables>({
queryRef: QueryReference<NoInfer<TData>, NoInfer<TVariables>>
) => ReactNode);
}) {
const resultPromise = getClient().query<TData, TVariables>({
...options,
// TODO: create a second Client instance only for `PreloadQuery` calls
// We want to prevent "client" data from leaking into our "RSC" cache,
// as that data should always be strictly separated.
fetchPolicy: "no-cache",
});
const resultPromise = getClient()
.query<TData, TVariables>({
...options,
// TODO: create a second Client instance only for `PreloadQuery` calls
// We want to prevent "client" data from leaking into our "RSC" cache,
// as that data should always be strictly separated.
fetchPolicy: "no-cache",
})
.then(sanitizeForTransport);
const transportedOptions = preparePreloadedQueryOptions(options);
return (
<SimulatePreloadedQuery<TData>
Expand All @@ -49,8 +52,13 @@ export function PreloadQuery<TData, TVariables extends OperationVariables>({
function preparePreloadedQueryOptions(
options: Parameters<typeof PreloadQuery>[0]["options"]
): TransportedOptions {
return {
const transportedOptions = {
...options,
query: printMinified(options.query),
};
return sanitizeForTransport(transportedOptions);
}

function sanitizeForTransport<T>(value: T) {
return JSON.parse(JSON.stringify(value)) as T;
}

0 comments on commit f9ea406

Please sign in to comment.