The typical stack I like to work in these days is Next.js with a custom express server, and in that server is an Apollo GraphQL layer so that I can make requests to the same server.

This means that the app is highly interlinked and the notion of microservices is out the door. Good riddance, anyway — they rack up costs.

The baseline server is something like so -

With the Apollo server looking something like this:

Where types, contexts, etc are defined elsewhere as a normal GraphQL setup goes. Don’t need to cover that here. So our Next.js app consumes data from this server and then Next does all sorts of magic making it isomorphic via Apollo Client.

Now, in order to actually use this data during the export it just takes some very basic scripting:

and in package.json, you’ll want to use ts-node export.ts . It should be fairly obvious what it’s doing:

Starts up a barebones express server.

Attaches the Apollo server link

Begins next export build process

build process Once done, it cleans up and closes out the server

When the server is up [on port 3k], our client link will consume the data that next uses to build the export.

For reference, here’s my usual apollo client setup for Next.js.