diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 055baf22..12b4dc66 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - version: ["latest", "next", "0.0.0-pr-11345-20231129164802"] + version: ["latest", "next"] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/package/package.json b/package/package.json index 2781a8f7..137e8e24 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/experimental-nextjs-app-support", - "version": "0.7.1", + "version": "0.8.0", "repository": { "url": "git+https://github.com/apollographql/apollo-client-nextjs" }, @@ -62,7 +62,7 @@ "vitest": "1.2.1" }, "peerDependencies": { - "@apollo/client": ">=3.8.0-rc || ^3.8.0 || >=3.9.0-alpha || >=3.9.0-beta || >=3.9.0-rc || ^3.9.0", + "@apollo/client": "^3.9.0", "next": "^13.4.1 || ^14.0.0", "react": "^18" }, diff --git a/package/src/ssr/NextSSRApolloClient.tsx b/package/src/ssr/NextSSRApolloClient.tsx index 8b1f9835..78e6b2a3 100644 --- a/package/src/ssr/NextSSRApolloClient.tsx +++ b/package/src/ssr/NextSSRApolloClient.tsx @@ -17,19 +17,9 @@ import { } from "./ApolloRehydrateSymbols"; import invariant from "ts-invariant"; -function getQueryManager(client: ApolloClient): Pick< - QueryManager, - "generateQueryId" | "fetchQuery" | "stopQuery" | "getDocumentInfo" -> & { - fetchCancelFns: QueryManager["fetchCancelFns"]; - inFlightLinkObservables: - | Map>> - | (import("@wry/trie").Trie<{ - observable?: Observable>; - }> & { - remove(...args: any[]): void; - }); -} { +function getQueryManager( + client: ApolloClient +): QueryManager { return client["queryManager"]; } @@ -96,32 +86,13 @@ export class NextSSRApolloClient< const printedServerQuery = print(query); const queryManager = getQueryManager(this); - let hasRunningQuery: boolean; - let byVariables: Map | undefined; - - if ("lookup" in queryManager["inFlightLinkObservables"]) { - hasRunningQuery = !!queryManager["inFlightLinkObservables"].peek( + if ( + !queryManager["inFlightLinkObservables"].peek( printedServerQuery, varJson - )?.observable; - } else { - byVariables = - queryManager["inFlightLinkObservables"].get( - printedServerQuery - ) || new Map(); - - queryManager["inFlightLinkObservables"].set( - printedServerQuery, - byVariables - ); - - hasRunningQuery = byVariables.has(varJson); - } - - if (!hasRunningQuery) { + )?.observable + ) { let simulatedStreamingQuery: SimulatedQueryInfo, - // eslint-disable-next-line prefer-const - observable: Observable, fetchCancelFn: (reason: unknown) => void; const cleanup = () => { @@ -130,19 +101,10 @@ export class NextSSRApolloClient< ) queryManager["fetchCancelFns"].delete(cacheKey); - if (byVariables) { - if (byVariables.get(varJson) === observable) - byVariables.delete(varJson); - } else if ( - "lookup" in queryManager["inFlightLinkObservables"] - ) { - queryManager["inFlightLinkObservables"].remove( - printedServerQuery, - varJson - ); - } else { - throw new Error("unexpected shape of QueryManager"); - } + queryManager["inFlightLinkObservables"].remove( + printedServerQuery, + varJson + ); if ( this.simulatedStreamingQueries.get(cacheKey) === @@ -160,7 +122,7 @@ export class NextSSRApolloClient< promise.finally(cleanup); - observable = new Observable((observer) => { + const observable = new Observable((observer) => { promise .then((result) => { observer.next(result); @@ -170,16 +132,11 @@ export class NextSSRApolloClient< observer.error(err); }); }); - if (byVariables) { - byVariables.set(varJson, observable); - } else if ("lookup" in queryManager["inFlightLinkObservables"]) { - queryManager["inFlightLinkObservables"].lookup( - printedServerQuery, - varJson - ).observable = observable; - } else { - throw new Error("unexpected shape of QueryManager"); - } + + queryManager["inFlightLinkObservables"].lookup( + printedServerQuery, + varJson + ).observable = observable; queryManager["fetchCancelFns"].set( cacheKey, diff --git a/yarn.lock b/yarn.lock index 59826637..33253811 100644 --- a/yarn.lock +++ b/yarn.lock @@ -100,7 +100,7 @@ __metadata: typescript: "npm:5.3.3" vitest: "npm:1.2.1" peerDependencies: - "@apollo/client": ">=3.8.0-rc || ^3.8.0 || >=3.9.0-alpha || >=3.9.0-beta || >=3.9.0-rc || ^3.9.0" + "@apollo/client": ^3.9.0 next: ^13.4.1 || ^14.0.0 react: ^18 languageName: unknown