Next.js Discord

Discord Forum

How to disable graphql cache

Unanswered
Karelian Bear Dog posted this in #help-forum
Open in Discord
Karelian Bear DogOP
I am using nextjs with strapi with graphql and in my production when I change strapi data it is not reflecting on the website what could be the solution here is my apollo client
import {
  ApolloClient,
  InMemoryCache,
  type NormalizedCacheObject,
  HttpLink,
  ApolloLink,
} from "@apollo/client";

const httpLink = new HttpLink({
  uri: process.env.STRAPI_GRAPHQL_URL,
  fetch: function (uri, options) {
    return fetch(uri, {
      ...(options ?? {}),
      headers: {
        ...(options?.headers ?? {}),
      },
      next: {
        revalidate: 1,
      },
    });
  },
});

const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
  cache: new InMemoryCache(),
  link: ApolloLink.from([httpLink]),
  defaultOptions: {
    query: {
      fetchPolicy: "no-cache",
      errorPolicy: "all",
    },
    watchQuery: {
      fetchPolicy: "no-cache",
      errorPolicy: "all",
    },
  },
});

export default client;

0 Replies