I am using woocommerce graph ql to query products on my Next JS frontend. The issue is that sometimes when I update a product on the wordpress dashboard, it takes time to update on the frontend (around 2minute to 10 minute) or unless I refresh. How can I make this faster and automatic. WordPress site is on Hostinger and Frontend is on Vercel
Version 1.3.8 | By WPGraphQL
Version 0.8.1 | WPGraphQL WooCommerce (WooGraphQL)
import {
ApolloClient,
ApolloLink,
InMemoryCache,
createHttpLink,
} from "@apollo/client";
/**
* Middleware operation
* If we have a session token in localStorage, add it to the GraphQL request as a Session header.
*/
export const middleware = new ApolloLink((operation, forward) => {
/**
* If session data exist in local storage, set value as session header.
*/
const session = process.browser
? localStorage.getItem("my-app-session")
: null;
if (session) {
operation.setContext(() => ({
headers: {
"woocommerce-session": `Session ${session}`,
},
}));
}
return forward(operation);
});
/**
* Afterware operation.
*
* This catches the incoming session token and stores it in localStorage, for future GraphQL requests.
*/
export const afterware = new ApolloLink((operation, forward) => {
return forward(operation).map((response) => {
if (!process.browser) {
return response;
}
/**
* Check for session header and update session in local storage accordingly.
*/
const context = operation.getContext();
const {
response: { headers },
} = context;
const session = headers.get("woocommerce-session");
if (session) {
// Remove session data if session destroyed.
if ("false" === session) {
localStorage.removeItem("my-app-session");
// Update session new data if changed.
} else if (localStorage.getItem("my-app-sessionn") !== session) {
localStorage.setItem(
"moutai-session",
headers.get("woocommerce-session")
);
}
}
return response;
});
});
// Apollo GraphQL client.
const client = new ApolloClient({
link: middleware.concat(
afterware.concat(
createHttpLink({
uri: `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/graphql`,
fetch,
credentials: "include",
})
)
),
cache: new InMemoryCache(),
});
export default client;
collections/index.tsx
import { CollectionLists } from "@/components/sections/CollectionLists";
import { Product } from "@/actions";
import client from "@/ApolloClient";
import PRODUCTS_AND_CATEGORIES_QUERY from "@/queries/product-and-categories";
export default function AllCollections({ products }: { products: Product[] }) {
return (
<section className="mx-auto flex flex-col uppercase bg-accent-600 lg:pt-32 pt-20">
<CollectionHeader title={"Shop"} desc={"Store Description"} />
<CollectionLists
backgroundColorClass={"bg-accent-1000"}
products={products}
slug={"Products"}
/>
</section>
);
}
export async function getStaticProps() {
const { data } = await client.query({
query: PRODUCTS_AND_CATEGORIES_QUERY,
});
return {
props: {
products: data?.products?.nodes ? data.products.nodes : [],
},
revalidate: 1,
};
}```
Tried Clearing local storage immediately I added product and setting revalidate to 1. Still no progress