Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// get fetch instance
const fetchInstance = options.fetch || getFetchInstance();
if (!fetchInstance) {
throw new Error(
'No `fetch` instance was found. It could be because your browser requires a polyfill, or maybe you are trying to run this in Node.js, in which case you should use node-fetch or equivalent. You can find more information here: https://github.com/BlueBrain/nexus-js/tree/master/packages/nexus-sdk#nodejs-support',
);
}
// check abort controller presence
if (!getAbortControllerInstance()) {
throw new Error(
'No `AbortController` instance was found. It could be because your browser requires a polyfill, or maybe you are trying to run this in Node.js, in which case you should use abort-controller or equivalent. You can find more information here: https://github.com/BlueBrain/nexus-js/tree/master/packages/nexus-sdk#nodejs-support',
);
}
const defaultLinks = [triggerFetch(fetchInstance)];
options.token && defaultLinks.unshift(setToken(options.token));
const links = options.links
? [...options.links, ...defaultLinks]
: defaultLinks;
const requestHandler = pipe(links);
const defaultContext = { uri: options.uri };
const context: NexusContext = options.context
? { ...options.context, ...defaultContext }
: defaultContext;
const fetchers: Fetchers = {
httpGet: operation => toPromise(requestHandler(operation)),
httpPost: operation =>
toPromise(pipe([setMethod('POST'), requestHandler])(operation)),
httpPut: operation =>
toPromise(pipe([setMethod('PUT'), requestHandler])(operation)),
httpPatch: operation =>