2020-07-20 10:05:47 +00:00
|
|
|
import NodeHttpAdapter from "@pollyjs/adapter-node-http";
|
|
|
|
import { Polly } from "@pollyjs/core";
|
|
|
|
import FSPersister from "@pollyjs/persister-fs";
|
|
|
|
import { InMemoryCache } from "apollo-cache-inmemory";
|
|
|
|
import ApolloClient from "apollo-client";
|
|
|
|
import { BatchHttpLink } from "apollo-link-batch-http";
|
|
|
|
import fetch from "node-fetch";
|
|
|
|
import path from "path";
|
|
|
|
import { setupPolly } from "setup-polly-jest";
|
|
|
|
|
2020-07-21 13:55:50 +00:00
|
|
|
Polly.register(NodeHttpAdapter);
|
|
|
|
Polly.register(FSPersister);
|
|
|
|
|
2020-07-20 10:05:47 +00:00
|
|
|
function setupApi() {
|
2020-07-28 11:01:28 +00:00
|
|
|
if (!process.env.API_URI) {
|
|
|
|
throw new Error("Environment variable API_URI not set");
|
|
|
|
}
|
|
|
|
|
2020-07-20 10:05:47 +00:00
|
|
|
setupPolly({
|
|
|
|
adapters: ["node-http"],
|
|
|
|
persister: "fs",
|
|
|
|
persisterOptions: {
|
|
|
|
fs: {
|
|
|
|
recordingsDir: path.resolve(__dirname, "../recordings")
|
|
|
|
}
|
2020-07-21 13:55:50 +00:00
|
|
|
}
|
2020-07-20 10:05:47 +00:00
|
|
|
});
|
|
|
|
const cache = new InMemoryCache();
|
|
|
|
const link = new BatchHttpLink({
|
|
|
|
// @ts-ignore
|
|
|
|
fetch,
|
2020-07-28 10:33:55 +00:00
|
|
|
uri: process.env.API_URI
|
2020-07-20 10:05:47 +00:00
|
|
|
});
|
|
|
|
const apolloClient = new ApolloClient({
|
|
|
|
cache,
|
|
|
|
link
|
|
|
|
});
|
|
|
|
|
|
|
|
return apolloClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default setupApi;
|