Apollo-link: Issues with apollo-link-http-common checkFetcher

Created on 17 Feb 2018  路  1Comment  路  Source: apollographql/apollo-link

Here it is in its current state:

export const checkFetcher = (fetcher: GlobalFetch['fetch']) => {
  if (!fetcher && typeof fetch === 'undefined') {
    let library: string = 'unfetch';
    if (typeof window === 'undefined') library = 'nodefetch';
    throw new Error(`
fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/${library}.
For example:
import fetch from '${library}';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });`);
  }
};
  1. The package nodefetch does not exist.
  2. If people are running apollo links on the server, it is most likely because they are server-side-rendering. In that situation telling them to import fetch from 'node-fetch' would break the client. The right advice is to just use import 'isomorphic-unfetch' and not mess around with passing fetch into the link config.
  3. Showing instructions for apollo-link-http in the message might confuse people using other http packages, such as batching or uploads.
  4. The multiline error message string is 301 bytes, that can't be minified. It's a developer warning that bloats production bundles. There are ways to make warnings only show up in the dev environment (i.e. invariant).
  5. The hard line wraps won't look good in narrow or wide consoles.
  6. https://www.npmjs.com/package/ could be https://npm.im/, along with other tweaks to shorten the message.

I already shared some of these points:

Most helpful comment

@jaydenseric Here to point out that I stumbled upon this today and installing and importing isomorphic-unfetch got rid of the warning for me.

npm i isomorphic-unfetch

And, on the server:

// Importing `isomorphic-unfetch` due to `apollo-link-http` raising
// a warning of not having `fetch` globally available.
// @see https://github.com/apollographql/apollo-link/issues/493
import 'isomorphic-unfetch';
import { createHttpLink } from 'apollo-link-http';

>All comments

@jaydenseric Here to point out that I stumbled upon this today and installing and importing isomorphic-unfetch got rid of the warning for me.

npm i isomorphic-unfetch

And, on the server:

// Importing `isomorphic-unfetch` due to `apollo-link-http` raising
// a warning of not having `fetch` globally available.
// @see https://github.com/apollographql/apollo-link/issues/493
import 'isomorphic-unfetch';
import { createHttpLink } from 'apollo-link-http';
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lobosan picture lobosan  路  3Comments

valerybugakov picture valerybugakov  路  5Comments

Nickersoft picture Nickersoft  路  3Comments

ignivalancy picture ignivalancy  路  5Comments

Kisepro picture Kisepro  路  4Comments