const fetch = require('node-fetch'); import { createHttpLink } from 'apollo-link-http'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { ApolloClient } from 'apollo-client'; import { setContext } from 'apollo-link-context'; export function getClient(apiUrl, apiKey): ApolloClient { const httpLink = createHttpLink({ uri: apiUrl, fetch }); const authLink = setContext((_, {headers}) => { return { headers: { ...(headers || {}), 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-FloomX-Internal-Key': apiKey } }; }); return new ApolloClient({ link: authLink.concat(httpLink), cache: new InMemoryCache() }); } export const client: ApolloClient = getClient(process.env.FLOOMX_API_URL_X, process.env.WEBSITE_GEN_API_KEY_X);