logaretm / villus

🏎 A tiny and fast GraphQL client for Vue.js
https://villus.dev
MIT License
790 stars 31 forks source link

Deploying to Vercel Edge function #192

Open babyradJiri opened 1 year ago

babyradJiri commented 1 year ago

When deploying Nuxt 3 project to Vercel Edge function, I get an error "Could not resolve a fetch() method, you should provide one". I managed to fix this by setting up Villus like this:

import { createClient } from "villus";
import { fetch as fetchPlugin } from "villus";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(
    createClient({
      url: `${nuxtApp.$config.public.backendUrl}/graphql`,
      use: [fetchPlugin({ fetch })],
    }),
  );
});

By passing fetch to renamed fetch plugin, all works. I think this shouldn't be required and is probably issue with resolveGlobalFetch function not finding Vercel fetch. I haven't figured out how to modify it tho.