import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client"; import { setContext } from "@apollo/client/link/context"; const httpLink = createHttpLink({ uri: process.env.NEXT_PUBLIC_SALEOR_API_URL || "http://localhost:8000/graphql/", }); const authLink = setContext((_, { headers }) => { // Saleor doesn't require auth for public queries // Add auth token here if needed for admin operations return { headers: { ...headers, "Content-Type": "application/json", }, }; }); export const saleorClient = new ApolloClient({ link: authLink.concat(httpLink), cache: new InMemoryCache({ typePolicies: { Query: { fields: { products: { keyArgs: ["channel", "filter"], merge(existing, incoming) { if (!existing) return incoming; return { ...incoming, edges: [...existing.edges, ...incoming.edges], }; }, }, }, }, }, }), defaultOptions: { watchQuery: { fetchPolicy: "cache-first", }, query: { fetchPolicy: "cache-first", }, }, }); export default saleorClient;