Zend certified PHP/Magento developer

Error in Apollo Query to Magento GraphQL API in Next JS app

I’m putting together a Next JS (9.x) frontend pulling in data from the Magento GraphQL API (2.3.2) using Apollo. My queries are returning an error on initial navigation but, but will render the data when the page is refreshed. I’m thinking there’s an issue with getInitialProps running on the server. My /lib/apollo.js file is below where I set up the HOC to wrap components with queries. Any help would be greatly appreciated.

import { ApolloProvider } from '@apollo/react-hooks';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import Head from 'next/head';
import fetch from 'isomorphic-unfetch';
import { HttpLink } from 'apollo-boost';

export function withApollo(PageComponent) {
  function WithApollo({ apolloClient, apolloState, ...pageProps }) {
    const client = apolloClient || initApolloClient(apolloState);
    return (
      
        
      
    );
  }

  WithApollo.getInitialProps = async function(ctx) {
    const { AppTree } = ctx;
    const apolloClient = (ctx.apolloClient = initApolloClient());
    let pageProps = {};
    if (PageComponent.getInitialProps) {
      pageProps = await PageComponent.getInitialProps(ctx);
    }
    if (typeof window === 'undefined') {
      if (ctx.res && ctx.res.finished) {
        return pageProps;
      }
      try {
        const { getDataFromTree } = await import('@apollo/react-ssr');
        await getDataFromTree(
          
        );
      } catch (err) {
        console.error('Error while running `getDataFromTree`', error);
      }
      Head.rewind();
    }
    const apolloState = apolloClient.cache.extract();
    return {
      ...pageProps,
      apolloState,
    };
  };

  return WithApollo;
}
const link = new HttpLink({
  uri: 'http://scrubs.local.test/graphql',
  fetch,
});
function initApolloClient(initialState = {}) {
  const ssrMode = typeof window === 'undefined';
  const cache = new InMemoryCache().restore(initialState || {});

  const client = new ApolloClient({
    ssrMode,
    link,
    cache,
  });
  return client;
}