next-with-apollo
Version:
Apollo HOC for Next.js
27 lines (26 loc) • 862 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// Polyfill fetch
require("isomorphic-unfetch");
var _apolloClient;
var ssrMode = typeof window === 'undefined';
function initApollo(clientFn, options) {
if (!clientFn) {
throw new Error('[withApollo] the first param is missing and is required to get the ApolloClient');
}
if (ssrMode) {
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);
}