wp-graphql
wp-graphql copied to clipboard
feat: prev/next on edge
I've seem other GraphQL APIs on CMSs provide prev
and next
connections on a node edge. This would be helpful in my case for creating page level navigation for next post and previous post. I've solved this in JS for now but it would be nice for these to be available in query. It would look something like:
query {
posts {
edges {
next {
#WpGraphql_Post
}
prev {
#WpGraphql_Post
}
node {
#WpGraphql_Post
}
}
}
}
@moonmeister I have a GIST that may apply here: https://gist.github.com/jasonbahl/55a6eff4cd67ce639ecd2d9989fef4cc
I've been thinking about adding support for this, but haven't landed on an ideal implementation. I plan on doing some work on Connections in an upcoming release, so this could be a good time to dive more into this.
That gist is for older version of WP-GQL I think, this is an updated version that we use all the time: https://github.com/funkhaus/stackhaus-backend/blob/master/functions/gql-functions.php#L32-L146
@drewbaker am curious which file do you add that code in your gist?
In your themes functions.php file
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue.
I'm hoping this can also apply to single post queries the way that WPGraphql Next-Previous Post allows:
query Post {
post(id: 1, idType: DATABASE_ID) {
title
next {
title
}
previous {
title
}
}
}
Additionally, for my use case I need to paginate based on a post category/tag. So for a given post I'd like the next and prev post to behave is if it's only paginating across the set of posts tagged with foo
for example.