0

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!

G6ix
  • 164
  • 1
  • 8

2 Answers2

1

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
   }
  }
Čedomir Babić
  • 522
  • 4
  • 12
  • Thanks @ČedomirBabić for your help! I probably gained a few white hairs trying to solve this lol! – G6ix Feb 12 '23 at 20:15
0

You can get the total number of post like this.

   query GetPost {
       postConnection(stage: PUBLISHED) {
           aggregate {
               count
           }
       }
   }
   
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Dhaifallah Aug 03 '23 at 14:00
  • This does not appear to answer the question. The question asks about fetching more than 10 posts, your answer explains how to get the post count. – LW001 Aug 04 '23 at 19:27