Hi, I need to fetch the data of the “next post” on each post. This is for displaying a section to preview the next post.
For example, if I have post-01, post-02, post-03;
When querying the data of post-02, I would need to be able to get some data from post-03 (slug, title, image, …).
I worked with other CMS’s in the past that would “prev” & “next” keys available in GraphQL, but that’s not the case for Dato.
What would be the best approach here?
My current solution looks something like this:
query PostPage {
_allPostsMeta {
count
}
post(filter: {slug: {eq: "post-02"}}) {
slug
position
}
}
# $position = (data.post.position + 1) % data._allPostsMeta.count
query NextPost($position) {
nextPage: page(filter: {position: {eq: $position}}) {
slug
title
}
}