saleor-dashboard/testUtils/api.ts
Krzysztof Żuraw ac063c6410
Update Dockerfile (#2523)
Co-authored-by: Francisco Marques <franciscopcmarques@gmail.com>
2022-11-16 16:01:34 +01:00

50 lines
1.2 KiB
TypeScript

import { ApolloClient, InMemoryCache } from "@apollo/client";
import { BatchHttpLink } from "@apollo/client/link/batch-http";
import NodeHttpAdapter from "@pollyjs/adapter-node-http";
import { Polly } from "@pollyjs/core";
import FSPersister from "@pollyjs/persister-fs";
import { getApiUrl } from "@saleor/config";
import { createFetch } from "@saleor/sdk";
import path from "path";
import { setupPolly } from "setup-polly-jest";
Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);
function setupApi() {
setupPolly({
adapters: ["node-http"],
matchRequestsBy: {
headers: false,
url: {
hash: false,
hostname: false,
password: false,
pathname: false,
port: false,
protocol: false,
query: false,
username: false,
},
},
persister: "fs",
persisterOptions: {
fs: {
recordingsDir: path.resolve(__dirname, "../recordings"),
},
},
});
const cache = new InMemoryCache();
const link = new BatchHttpLink({
fetch: createFetch(),
uri: getApiUrl(),
});
const apolloClient = new ApolloClient({
cache,
link,
});
return apolloClient;
}
export default setupApi;