leonardomso/graphql-mongodb-server

How to sort / filter the posts

AntoninSlejska opened this issue · 2 comments

I have a simple request like this:

query {Posts{_id title date {published}}}

How can I sort the posts e.g. by publishing date and limit the number of posts? And how can I filter the posts, e.g. that I get only posts older than some date?

Hi! You should check out this link. I'm new to GraphQL and running onto the same issues, but they explain in a pretty simple way.

but basically your query should become something like

query {
  Posts(first: 10, offset: $cursor) {
    _id
    title
    date {
      published
    }
  }
}

Where you get $cursor controlled by your resolver indicating where should your pagination work.

Thanks Bruno!