How to use the cross-fetch/polyfill.fetch function in cross-fetch

To help you get started, we’ve selected a few cross-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProjectEvergreen / greenwood / packages / cli / src / graphql / cache.js View on Github external
const ApolloClient = require('apollo-boost').ApolloClient;
const createHttpLink = require('apollo-link-http').createHttpLink;
const fetch = require('cross-fetch/polyfill').fetch;
const fs = require('fs-extra');
const { gql } = require('apollo-server-express');
const InMemoryCache = require('apollo-cache-inmemory').InMemoryCache;
const path = require('path');

/* Extract cache server-side */
module.exports = async (req, { publicDir }) => {
  let cache = '';

  return new Promise(async(resolve, reject) => {
    try {
      const client = new ApolloClient({
        link: createHttpLink({
          uri: 'http://localhost:4000?q=internal', /* specific internal flag to prevent looping cache on request */
          fetch: fetch
        }),