logaretm / villus

🏎 A tiny and fast GraphQL client for Vue.js

Home Page:https://villus.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In Service Worker: Could not resolve a fetch() method

bravik opened this issue · comments

Tried to use villus to make a query in a service worker:

villus.esm.js:236 Uncaught Error: Could not resolve a fetch() method, you should provide one.
    at fetch (villus.esm.js:236:15)
    at defaultPlugins (villus.esm.js:337:49)
    at index.ts:22:12

villus.esm.js:

function fetch(opts) {
    const fetch = (opts === null || opts === void 0 ? void 0 : opts.fetch) || resolveGlobalFetch();
    if (!fetch) {
        throw new Error('Could not resolve a fetch() method, you should provide one.');
    }

Maybe self should be also checked here for workers:

  function resolveGlobalFetch() {
      if (typeof window !== 'undefined' && 'fetch' in window && window.fetch) {
          return window.fetch.bind(window);
      }
      if (typeof global !== 'undefined' && 'fetch' in global) {
          return global.fetch;
      }
      return undefined;
  }

closed by #161