From 96d6d42120dc3e1b4839d806a02515b6d7e38d3d Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 23 Nov 2021 12:35:20 -0800 Subject: [PATCH] Use persisted queries in dev, bc Next.js support We had previously configured the client to not bother to try a GET request for GraphQL queries, and just jump straight to POST instead, because the `vercel dev` server for create-react-app reloaded the backend code for every request anyway, which doubled the dev response time. The Next.js server is more efficient than this, and keeps some memory, so GET requests work similarly in dev as on prod now! (i.e. it fails the first time, but then succeeds on the second) In this change, we remove the code to skip `createPersistedQueryLink` in development, and instead always call it. We simplify the code accordingly, too. --- src/app/apolloClient.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/app/apolloClient.js b/src/app/apolloClient.js index d66be15..3df1923 100644 --- a/src/app/apolloClient.js +++ b/src/app/apolloClient.js @@ -208,22 +208,14 @@ for (const zone of cachedZones) { initialCache[`Zone:${zone.id}`] = { __typename: "Zone", ...zone }; } -const buildLink = (getAuth0) => { - let link = buildAuthLink(getAuth0); - if (process.env.NODE_ENV === "production") { - // In production, we send GET requests for queries, to enable CDN and - // browser caching. But in development, we skip it, because our dev server - // reloads the route from scratch on each request, so queries never get - // persisted, and the GET always fails and falls back to POST anyway. - link = link.concat( +const buildLink = (getAuth0) => + buildAuthLink(getAuth0) + .concat( createPersistedQueryLink({ useGETForHashedQueries: true, }) - ); - } - link = link.concat(httpLink); - return link; -}; + ) + .concat(httpLink); /** * apolloClient is the global Apollo Client instance we use for GraphQL