-
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
15 changed files
with
228 additions
and
73 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 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
15 changes: 15 additions & 0 deletions
15
integration-test/nextjs/src/app/rsc/dynamic/PreloadQuery/ClientChild.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,15 @@ | ||
"use client"; | ||
|
||
import { useSuspenseQuery } from "@apollo/client"; | ||
import { QUERY } from "./shared"; | ||
|
||
export function ClientChild() { | ||
const { data } = useSuspenseQuery(QUERY, { context: { error: "always" } }); | ||
return ( | ||
<ul> | ||
{data.products.map(({ id, title }) => ( | ||
<li key={id}>{title}</li> | ||
))} | ||
</ul> | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
integration-test/nextjs/src/app/rsc/dynamic/PreloadQuery/PreloadQuery.test.ts
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,41 @@ | ||
import { expect } from "@playwright/test"; | ||
import { test } from "../../../../../fixture"; | ||
|
||
test.describe("PreloadQuery", () => { | ||
test("query resolves on the server", async ({ page, blockRequest }) => { | ||
await page.goto( | ||
"http://localhost:3000/rsc/dynamic/PreloadQuery?errorIn=ssr,browser", | ||
{ | ||
waitUntil: "commit", | ||
} | ||
); | ||
|
||
await expect(page).toBeInitiallyLoading(true); | ||
await expect(page.getByText("loading")).not.toBeVisible(); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
|
||
test("query errors on the server, restarts in the browser", async ({ | ||
page, | ||
}) => { | ||
page.allowErrors?.(); | ||
await page.goto( | ||
"http://localhost:3000/rsc/dynamic/PreloadQuery?errorIn=rsc", | ||
{ | ||
waitUntil: "commit", | ||
} | ||
); | ||
|
||
await expect(page).toBeInitiallyLoading(true); | ||
|
||
await page.waitForEvent("pageerror", (error) => { | ||
return ( | ||
/* prod */ error.message.includes("Minified React error #419") || | ||
/* dev */ error.message.includes("Query failed upstream.") | ||
); | ||
}); | ||
|
||
await expect(page.getByText("loading")).not.toBeVisible(); | ||
await expect(page.getByText("Soft Warm Apollo Beanie")).toBeVisible(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
integration-test/nextjs/src/app/rsc/dynamic/PreloadQuery/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,29 @@ | ||
import { ApolloWrapper } from "@/app/cc/ApolloWrapper"; | ||
import { PreloadQuery } from "@apollo/client-react-streaming"; | ||
import { ClientChild } from "./ClientChild"; | ||
import { QUERY } from "./shared"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
import { getClient } from "../../client"; | ||
import { Suspense } from "react"; | ||
|
||
export default function Page({ searchParams }: { searchParams?: any }) { | ||
return ( | ||
<ApolloWrapper> | ||
<PreloadQuery | ||
options={{ | ||
query: QUERY, | ||
context: { | ||
delay: 1000, | ||
error: searchParams?.errorIn || undefined, | ||
}, | ||
}} | ||
getClient={getClient} | ||
> | ||
<Suspense fallback={<>loading</>}> | ||
<ClientChild /> | ||
</Suspense> | ||
</PreloadQuery> | ||
</ApolloWrapper> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
integration-test/nextjs/src/app/rsc/dynamic/PreloadQuery/shared.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,15 @@ | ||
import { TypedDocumentNode, gql } from "@apollo/client"; | ||
|
||
export const QUERY: TypedDocumentNode<{ | ||
products: { | ||
id: string; | ||
title: string; | ||
}[]; | ||
}> = gql` | ||
query dynamicProducts { | ||
products { | ||
id | ||
title | ||
} | ||
} | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ApolloLink, Observable } from "@apollo/client"; | ||
import { GraphQLError } from "graphql"; | ||
import * as entryPoint from "@apollo/client-react-streaming"; | ||
|
||
declare module "@apollo/client" { | ||
type Env = "ssr" | "browser" | "rsc"; | ||
export interface DefaultContext { | ||
error?: "always" | Env | `${Env},${Env}`; | ||
} | ||
} | ||
|
||
export const errorLink = new ApolloLink((operation, forward) => { | ||
const context = operation.getContext(); | ||
if ( | ||
context.error === "always" || | ||
("built_for_ssr" in entryPoint && | ||
context.error?.split(",").includes("ssr")) || | ||
("built_for_browser" in entryPoint && | ||
context.error?.split(",").includes("browser")) || | ||
("built_for_rsc" in entryPoint && context.error?.split(",").includes("rsc")) | ||
) { | ||
return new Observable((subscriber) => { | ||
subscriber.next({ | ||
data: null, | ||
errors: [new GraphQLError("Simulated error")], | ||
}); | ||
}); | ||
} | ||
return forward(operation); | ||
}); |
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
Oops, something went wrong.