UNPKG

next-with-apollo

Version:
26 lines (25 loc) 813 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // Polyfill fetch require("isomorphic-unfetch"); var _apolloClient; function initApollo(clientFn, options) { if (!clientFn) { throw new Error('[withApollo] the first param is missing and is required to get the ApolloClient'); } if (typeof window === 'undefined') { return getClient(clientFn, options); } if (!_apolloClient) { _apolloClient = getClient(clientFn, options); } return _apolloClient; } exports.default = initApollo; function getClient(clientFn, options) { if (options === void 0) { options = {}; } if (typeof clientFn !== 'function') { throw new Error('[withApollo] requires a function that returns an ApolloClient'); } return clientFn(options); }