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.
This commit is contained in:
Emi Matchu 2021-11-23 12:35:20 -08:00
parent 07d54b9a9e
commit 96d6d42120

View file

@ -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