Some checks failed
Build and Deploy / build (push) Has been cancelled
The merge function was concatenating products on each query, causing 4 products to become 8, then 12, etc. Changed to replace incoming data instead of merging.
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
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) {
|
|
return incoming;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
defaultOptions: {
|
|
watchQuery: {
|
|
fetchPolicy: "cache-first",
|
|
},
|
|
query: {
|
|
fetchPolicy: "cache-first",
|
|
},
|
|
},
|
|
});
|
|
|
|
export default saleorClient;
|