2

I am using Contentful CMS (community edition) with Next.js but Contentful Client keeps on vanishing the random data in response. Every time I need to change the status of entry to Unpublish and then again publishing it solves the issue. This is too disturbing because it prohibits the site to show data. Also, it's very hard to update entries and all linked data. Is anybody facing the same or have any solution?

export async function fetchEntries() {
  // const response = await client.getContentType("page");
  const entries = await client.getEntries();
  if (entries.items) return entries.items;
}

export async function getStaticProps() {
  const entries = await fetchEntries();
  let data = entries.filter((item) => item.sys.contentType.sys.id === "page" && item.fields.slug === "home");
  return {
    props: {
      data: data.length ? data[0] : null,
    },
  };
}

Contentful data is missing fields only sys object is shown You can have a look here

  • Can you provide an example showing how you fetch the code and explain how you structure your Next.js application? It's hard to give advice without knowing more details. :) – stefan judis Feb 24 '22 at 06:38
  • @stefanjudis Updated my question please have a look. Tried with filter as well using content id to fetch single entry. That didn't work either. – Junaid E. Rajput Feb 24 '22 at 18:07

1 Answers1

4

For someone in the future who encounters the same, here is the solution just add include property to your method where you are fetching the entries Read more here include resolves this package behind the scenes. Package is here contentful-resolve-response

const entry = await client.getEntries(
  { 
    content_type: "page",
    "fields.slug": "home",
    include: 10 
  }
);