-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"@apollo/client-react-streaming": "exec:./shared/build-client-react-streaming.cjs", | ||
"@apollo/experimental-nextjs-app-support": "exec:./shared/build-experimental-nextjs-app-support.cjs", | ||
"@apollo/client-integration-react-router": "exec:./shared/build-client-integration-react-router.cjs", | ||
"@apollo/client-integration-tanstack-start": "exec:./shared/build-client-integration-tanstack-start.cjs", | ||
"graphql": "17.0.0-alpha.2", | ||
"turbo-stream": "npm:@phryneas/[email protected]", | ||
"@tanstack/react-router": "patch:@tanstack/react-router@npm%3A1.91.3#~/../.yarn/patches/@tanstack-react-router-npm-1.91.3-8e077b923e.patch", | ||
|
@@ -14,7 +15,7 @@ | |
"*" | ||
], | ||
"scripts": { | ||
"build:libs": "find . -regextype posix-extended -regex '.*/node_modules/@apollo/(client-react-streaming|experimental-nextjs-app-support|client-integration-react-router)' -printf 'rm -r %p\n' -exec rm -r {} +; glob \"../.yarn/cache/@apollo-*exec*\" \"$HOME/.yarn/berry/cache/@apollo-*exec*\" --cmd='rm -v' ; yarn" | ||
"build:libs": "find . -regextype posix-extended -regex '.*/node_modules/@apollo/(client-react-streaming|experimental-nextjs-app-support|client-integration-react-router|client-integration-tanstack-start)' -printf 'rm -r %p\n' -exec rm -r {} +; glob \"../.yarn/cache/@apollo-*exec*\" \"$HOME/.yarn/berry/cache/@apollo-*exec*\" --cmd='rm -v' ; yarn" | ||
}, | ||
"devDependencies": { | ||
"glob": "^10.3.10" | ||
|
26 changes: 26 additions & 0 deletions
26
integration-test/shared/build-client-integration-tanstack-start.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
The integration tests need the latest version of the `@apollo/client-react-streaming` package. | ||
This script can be used with the `exec:` protocol (https://yarnpkg.com/protocol/exec) to build | ||
the package. | ||
*/ | ||
|
||
const { join } = require("node:path"); | ||
const { $, cd, retry, sleep } = /** @type {typeof import('zx')} */ ( | ||
require(require.resolve("zx", { paths: [process.env.PROJECT_CWD] })) | ||
); | ||
|
||
$.stdio = "inherit"; | ||
|
||
(async function run() { | ||
const monorepoRoot = join(process.env.PROJECT_CWD, ".."); | ||
const archive = join(monorepoRoot, "packages/tanstack-start/archive.tgz"); | ||
|
||
// give the main build script a chance to kick in | ||
await sleep(1000); | ||
|
||
await retry(120, "1s", () => $`test -f ${archive}`); | ||
|
||
cd(monorepoRoot); | ||
await $`tar -x -z --strip-components=1 -f ${archive} -C ${execEnv.buildDir}`; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,79 @@ | ||
import * as fs from "node:fs"; | ||
import { createFileRoute, useRouter } from "@tanstack/react-router"; | ||
import { createServerFn } from "@tanstack/start"; | ||
|
||
const filePath = "count.txt"; | ||
|
||
async function readCount() { | ||
return parseInt( | ||
await fs.promises.readFile(filePath, "utf-8").catch(() => "0") | ||
); | ||
} | ||
|
||
const getCount = createServerFn({ | ||
method: "GET", | ||
}).handler(() => { | ||
return readCount(); | ||
}); | ||
|
||
const updateCount = createServerFn({ method: "POST" }) | ||
.validator((d: number) => d) | ||
.handler(async ({ data }) => { | ||
const count = await readCount(); | ||
await fs.promises.writeFile(filePath, `${count + data}`); | ||
}); | ||
import { createFileRoute } from "@tanstack/react-router"; | ||
import { DEFERRED_QUERY } from "@integration-test/shared/queries"; | ||
import { | ||
useApolloClient, | ||
useQueryRefHandlers, | ||
useReadQuery, | ||
} from "@apollo/client/index.js"; | ||
import { useTransition } from "react"; | ||
import { reviveTransportedQueryRef } from "@apollo/client-react-streaming"; | ||
|
||
export const Route = createFileRoute("/")({ | ||
component: Home, | ||
loader: async () => await getCount(), | ||
loader: async ({ context: { preloadQuery } }) => { | ||
const queryRef = preloadQuery(DEFERRED_QUERY, { | ||
variables: { delayDeferred: 500 }, | ||
}); | ||
return { | ||
queryRef, | ||
}; | ||
}, | ||
}); | ||
|
||
function Home() { | ||
const router = useRouter(); | ||
const state = Route.useLoaderData(); | ||
const { queryRef } = Route.useLoaderData(); | ||
|
||
const ac = useApolloClient(); | ||
|
||
console.log({ queryRef }); | ||
// @ts-ignore | ||
reviveTransportedQueryRef(queryRef, ac); | ||
console.log({ queryRef }); | ||
|
||
const { refetch } = useQueryRefHandlers(queryRef); | ||
const [refetching, startTransition] = useTransition(); | ||
const { data } = useReadQuery(queryRef); | ||
const client = useApolloClient(); | ||
|
||
return ( | ||
<button | ||
type="button" | ||
onClick={() => { | ||
updateCount({ data: 1 }).then(() => { | ||
router.invalidate(); | ||
}); | ||
}} | ||
> | ||
Add 1 to {state}? | ||
</button> | ||
<> | ||
<ul> | ||
{data.products.map(({ id, title, rating }) => ( | ||
<li key={id}> | ||
{title} | ||
<br /> | ||
Rating:{" "} | ||
<div style={{ display: "inline-block", verticalAlign: "text-top" }}> | ||
{rating?.value || ""} | ||
<br /> | ||
{rating ? `Queried in ${rating.env} environment` : "loading..."} | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
<p>Queried in {data.env} environment</p> | ||
<button | ||
disabled={refetching} | ||
onClick={() => { | ||
client.cache.batch({ | ||
update(cache) { | ||
for (const product of data.products) { | ||
cache.modify({ | ||
id: cache.identify(product), | ||
fields: { | ||
rating: () => null, | ||
}, | ||
}); | ||
} | ||
}, | ||
}); | ||
startTransition(() => { | ||
refetch(); | ||
}); | ||
}} | ||
> | ||
{refetching ? "refetching..." : "refetch"} | ||
</button> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { routerWithApolloClient } from "./routerWithApolloClient.js"; | ||
export { ApolloClient } from "@apollo/client-react-streaming"; | ||
export { ApolloClient, InMemoryCache } from "@apollo/client-react-streaming"; |