GraphQL - Querying all documents of a custom type is missing newly created documents

Hi there!

I have a custom document type called 'Section' which up until recently I have been querying successfully like so:

{
  allSections {
    edges {
      node {
        _meta {
          uid
        }
      }
    }
  }
}

For a couple of days now every time I create a new Section document with a UID it is not being returned using the 'allSections' query.

However, I can query it directly using:

query SectionBySlug($section: String!, $lang: String!) {
  section(uid: $section, lang: $lang) {
    _meta {
      uid
    }
  }
}

With the query parameters:

{
  "section": "a-new-section",
  "lang": "en-gb"
}

I'm rather new to Prismic and GraphQL in general and I am a little perplexed why this has started happening.

If anyone can shed any light on the matter I would greatly appreciate the help!

Hello Adam,

Welcome to the community. I'd be happy to help you. I need more information from you. Can you please send me the url of your repository. You can share it with me personally by message, if you are not comfortable to share it here.

Thanks,
Priyanka

Hi Priyanka,

Thank you for getting back to me - I've sent you the url to the repository in question in a message.

Hi,

I have checked your repository, and I found that you have more than 20 documents of section custom_type, but graphql in Prismic returns max 20 documents at one time. For getting more than 20 documents, you nee to apply pagination which is described here.

In your case:

allSections {
         totalCount
        pageInfo {
          hasPreviousPage
          hasNextPage
          startCursor
          endCursor
        }
        edges {
          node {
            _meta {
              uid
            }
          }
        }
      }

After that, from results, you need to check if the param "hasNextPage" is true/false. If true, you need to take "endCursor" value from results and apply another query to get rest of the results from 2nd page.

 allSections (after:{Put your endCursor value here}, first: 10) {
 totalCount
pageInfo {
  hasPreviousPage
  hasNextPage
  startCursor
  endCursor
}
edges {
  node {
    _meta {
      uid
    }
  }
}

Please give this a try and let me know if you find any issue to solve it.

Thanks,
Priyanka

Ah, of course!

Following your instructions everything is working correctly.

Thank you for your help!

Great! Happy to help.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.