nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
929 stars 194 forks source link

_isomorphicFetch is not defined #611

Open spaceninja opened 2 months ago

spaceninja commented 2 months ago

Environment

Describe the bug

I'm using a custom fetch function in httpLinkOptions as detailed here: https://www.apollographql.com/docs/react/api/link/apollo-link-http/#customizing-fetch

Expected behaviour

// nuxt.config.ts:
import apolloConfig from './apollo-config';
export default defineNuxtConfig({
  apollo: apolloConfig,
  modules: ['@nuxtjs/apollo'],
});
// apollo-config.ts
import fetch from 'isomorphic-fetch';
export default {
  clients: {
    default: {
      httpEndpoint: process.env.NUXT_DATOCMS_GRAPHQL_URL,
      httpLinkOptions: {
        headers: {
          Authorization: `Bearer ${process.env.NUXT_DATOCMS_TOKEN}`,
        },
        fetch: (uri: string, options: any) => {
          const fetchBody = JSON.parse(options.body);
          // do some stuff to modify fetchBody
          options.body = JSON.stringify(fetchBody);
          return fetch(uri, options);
        },
      },
    },
  },
};
// example.vue
import sampleQuery from 'sample.gql';
const {
  data: sampleData,
  pending: sampleLoading,
  error: sampleError,
} = useAsyncQuery(sampleQuery);

With this example, sampleError comes back with "_isomorphicFetch is not defined"

After a bit of digging, this is the NetworkError field on the error returned by Apollo: https://www.apollographql.com/docs/react/api/link/apollo-link-error#networkerror

I don't get any console or server errors.

Reproduction

No response

Additional context

No response

Logs

No response