-
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.
restart simulated streamed request on stream close
- Loading branch information
Showing
9 changed files
with
251 additions
and
71 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
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
import { expect } from "@playwright/test"; | ||
import { test } from "../../../../fixture"; | ||
|
||
test.describe("CC dynamic", () => { | ||
test.describe("useSuspenseQuery", () => { | ||
test("one query", async ({ page, blockRequest }) => { | ||
await page.goto("http://localhost:3000/cc/dynamic/useSuspenseQuery", { | ||
waitUntil: "commit", | ||
}); | ||
|
||
await expect(page).toBeInitiallyLoading(false); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
}); | ||
test.describe("useBackgroundQuery", () => { | ||
test("one query", async ({ page, blockRequest }) => { | ||
await page.goto("http://localhost:3000/cc/dynamic/useBackgroundQuery", { | ||
waitUntil: "commit", | ||
}); | ||
|
||
await expect(page).toBeInitiallyLoading(true); | ||
await expect(page.getByText("loading")).not.toBeVisible(); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
|
||
// this will close the connection before the final result is received, so it can never be forwarded | ||
test("no `useReadQuery` on the server", async ({ page }) => { | ||
await page.goto( | ||
"http://localhost:3000/cc/dynamic/useBackgroundQueryWithoutSsrReadQuery", | ||
{ | ||
waitUntil: "commit", | ||
} | ||
); | ||
|
||
await expect(page.getByText("rendered on server")).toBeVisible(); | ||
await expect(page.getByText("rendered on client")).toBeVisible(); | ||
await expect(page.getByText("loading")).toBeVisible(); | ||
await expect(page.getByText("loading")).not.toBeVisible(); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
}); | ||
test.describe("useQuery", () => { | ||
test("without cache value", async ({ page }) => { | ||
await page.goto("http://localhost:3000/cc/dynamic/useQuery", { | ||
waitUntil: "commit", | ||
}); | ||
|
||
await expect(page).toBeInitiallyLoading(true); | ||
await expect(page.getByText("loading")).not.toBeVisible(); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
|
||
test("with cache value", async ({ page }) => { | ||
await page.goto("http://localhost:3000/cc/dynamic/useQueryWithCache", { | ||
waitUntil: "commit", | ||
}); | ||
|
||
await expect(page).toBeInitiallyLoading(false); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
integration-test/src/app/cc/dynamic/useBackgroundQueryWithoutSsrReadQuery/page.tsx
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,52 @@ | ||
"use client"; | ||
|
||
import { | ||
useBackgroundQuery, | ||
useReadQuery, | ||
} from "@apollo/experimental-nextjs-app-support/ssr"; | ||
import type { TypedDocumentNode } from "@apollo/client"; | ||
import { gql, QueryReference } from "@apollo/client"; | ||
import { Suspense, useState, useEffect } from "react"; | ||
|
||
interface Data { | ||
products: { | ||
id: string; | ||
title: string; | ||
}[]; | ||
} | ||
|
||
const QUERY: TypedDocumentNode<Data> = gql` | ||
query dynamicProducts { | ||
products { | ||
id | ||
title | ||
} | ||
} | ||
`; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export default function Page() { | ||
const [queryRef] = useBackgroundQuery(QUERY, { context: { delay: 2000 } }); | ||
const [isClient, setIsClient] = useState(false); | ||
useEffect(() => setIsClient(true), []); | ||
return ( | ||
<> | ||
{isClient ? "rendered on client" : "rendered on server"} | ||
<Suspense fallback={<p>loading</p>}> | ||
{isClient ? <DisplayData queryRef={queryRef} /> : null} | ||
</Suspense> | ||
</> | ||
); | ||
} | ||
|
||
function DisplayData({ queryRef }: { queryRef: QueryReference<Data> }) { | ||
const { data } = useReadQuery(queryRef); | ||
return ( | ||
<ul> | ||
{data.products.map(({ id, title }) => ( | ||
<li key={id}>{title}</li> | ||
))} | ||
</ul> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { expect } from "@playwright/test"; | ||
import { test } from "../../../../fixture"; | ||
|
||
test.describe("CC static", () => { | ||
test.describe("useSuspenseQuery", () => { | ||
test("one query", async ({ page, blockRequest }) => { | ||
await page.goto("http://localhost:3000/cc/static/useSuspenseQuery", { | ||
waitUntil: "commit", | ||
}); | ||
|
||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test.describe("useBackgroundQuery", () => { | ||
// this will close the connection before the final result is received, so it can never be forwarded | ||
test("no `useReadQuery` on the server", async ({ page }) => { | ||
await page.goto( | ||
"http://localhost:3000/cc/static/useBackgroundQueryWithoutSsrReadQuery", | ||
{ | ||
waitUntil: "commit", | ||
} | ||
); | ||
|
||
await expect(page.getByText("rendered on server")).toBeVisible(); | ||
await expect(page.getByText("rendered on client")).toBeVisible(); | ||
await expect(page.getByText("loading")).toBeVisible(); | ||
await expect(page.getByText("loading")).not.toBeVisible(); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
integration-test/src/app/cc/static/useBackgroundQueryWithoutSsrReadQuery/page.tsx
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,50 @@ | ||
"use client"; | ||
|
||
import { | ||
useBackgroundQuery, | ||
useReadQuery, | ||
} from "@apollo/experimental-nextjs-app-support/ssr"; | ||
import type { TypedDocumentNode } from "@apollo/client"; | ||
import { gql, QueryReference } from "@apollo/client"; | ||
import { Suspense, useState, useEffect } from "react"; | ||
|
||
interface Data { | ||
products: { | ||
id: string; | ||
title: string; | ||
}[]; | ||
} | ||
|
||
const QUERY: TypedDocumentNode<Data> = gql` | ||
query dynamicProducts { | ||
products { | ||
id | ||
title | ||
} | ||
} | ||
`; | ||
|
||
export default function Page() { | ||
const [queryRef] = useBackgroundQuery(QUERY, { context: { delay: 2000 } }); | ||
const [isClient, setIsClient] = useState(false); | ||
useEffect(() => setIsClient(true), []); | ||
return ( | ||
<> | ||
{isClient ? "rendered on client" : "rendered on server"} | ||
<Suspense fallback={<p>loading</p>}> | ||
{isClient ? <DisplayData queryRef={queryRef} /> : null} | ||
</Suspense> | ||
</> | ||
); | ||
} | ||
|
||
function DisplayData({ queryRef }: { queryRef: QueryReference<Data> }) { | ||
const { data } = useReadQuery(queryRef); | ||
return ( | ||
<ul> | ||
{data.products.map(({ id, title }) => ( | ||
<li key={id}>{title}</li> | ||
))} | ||
</ul> | ||
); | ||
} |
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
Oops, something went wrong.