saleor-dashboard/testUtils/api.ts
Krzysztof Żuraw 373c9e9ac3
Add sidebar feature flag (#3019)
Co-authored-by: andrzejewsky <vox3r69@gmail.com>
2023-01-23 12:16:02 +01:00

46 lines
1.1 KiB
TypeScript

import { ApolloClient, InMemoryCache } from "@apollo/client";
import { BatchHttpLink } from "@apollo/client/link/batch-http";
import { getApiUrl } from "@dashboard/config";
import NodeHttpAdapter from "@pollyjs/adapter-node-http";
import FSPersister from "@pollyjs/persister-fs";
import { createFetch } from "@saleor/sdk";
import path from "path";
import { setupPolly } from "setup-polly-jest";
function setupApi() {
setupPolly({
adapters: [NodeHttpAdapter],
matchRequestsBy: {
headers: false,
url: {
hash: false,
hostname: false,
password: false,
pathname: false,
port: false,
protocol: false,
query: false,
username: false,
},
},
persister: FSPersister,
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;