'CraftCMS GraphQL use next and prev interfaces

I'm using CraftCMS as a headless CMS. My single blog pages will have a next and previous button inside the page.

Below is a trimmed down version of my reqular query along with how i've tried to get the next and previous blog entries. The documentation specifies that prev and next interfaces are extensions of the EntryInterface but don't go in to more detail of what parameters need to be passed. (I've hard coded an ID for testing but this will need to work with the $slug variable which is given on query request.)

query ($slug: [String]) {
  blogPost: entry(section: "blog", slug: $slug) {
    __typename
    ... on blog_blog_Entry {
      id
      title
      next(nextSiblingOf: 11){
        id
        title
      }
      prev(prevSiblingOf: 11){
        id
        title
      }
    }
  }
}

Could someone point me in the right direction of how to get these entries, currently all I'm getting returned is null.



Solution 1:[1]

You can give this a try this should work.

query getEntryData($id: Int) {
  prevEntry: entry(prevSiblingOf: $id) {
    id
    title
    slug
    uri
  }
  nextEntry: entry(nextSiblingOf: $id) {
    id
    title
    slug
    uri
  }
  entryData: entry(section: blog, id: [$id]) {
    id
    title
    slug
    uri
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dotsquares