Headless CMS GraphQL NextJS Project Post Limit Issue

141 views Asked by At

I have a Headless cms project I created using GraphQl, NextJS and Hygraph. I'm also using NPM Graphql-request. I'm having issues "receiving" more than 10 posts on my project. So far I had less then 10 posts on my site, but now that I posted more, I'm simply not receiving the extra ones. I did some research but I can't seem to find the solution!

Here's what I got:

const QUERY = gql`
  {
    posts {
      title
      id
      slug
      datePublished
      mobileCoverPhoto {
        url
      }
      coverPhoto {
        id
        url
      }
      category
      imageAtlTag
      author {
        id
        name
        avatar {
          url
        }
      }
      content {
        text
        html
      }
    }
  }
`;

Everything works fine until post #10 only. Thanks everyone for helping!

2

There are 2 answers

1
Čedomir Babić On BEST ANSWER

10 is the default number of fetched posts. If you want to specify the number of posts you need to do it like this:

 posts(first: 10) {
   nodes {
     title
    slug
   }
  }
2
MYat mIN On

You can get the total number of post like this.

   query GetPost {
       postConnection(stage: PUBLISHED) {
           aggregate {
               count
           }
       }
   }