wp-graphql icon indicating copy to clipboard operation
wp-graphql copied to clipboard

feat: prev/next on edge

Open moonmeister opened this issue 5 years ago • 7 comments

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 avatar Jan 24 '20 18:01 moonmeister

@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.

jasonbahl avatar Jan 24 '20 18:01 jasonbahl

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 avatar Feb 25 '20 19:02 drewbaker

@drewbaker am curious which file do you add that code in your gist?

parkerproject avatar Feb 28 '20 04:02 parkerproject

In your themes functions.php file

drewbaker avatar Feb 28 '20 04:02 drewbaker

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.

stale[bot] avatar Aug 03 '22 00:08 stale[bot]

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.

stale[bot] avatar Sep 02 '22 01:09 stale[bot]

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.

nireno avatar Oct 20 '22 14:10 nireno