Filtering

Another important Hackernews feature is searching the links, so you’re going to be adding support for that now. You already know that it’s possible to pass input data to mutations, via arguments. Now you’re going to use this same concept to apply optional filters to the existing allLinks query.

For this part of the tutorial, we are going to use SearchObject::Plugin::GraphQL, gem used for making more advanced GraphQL search/filter resolvers.

This would install SearchObject and you can use it.

This resolver contains all logic related to find links. Over time you can add more rules.

SearchObject can be used as a GraphQL::Schema::Resolver.

Try your new filter out now:

Try your new filter out

You can even do more complicated searches:

You can even do more complicated searches

Next Chapter

Pagination

Learn best practices for implementing limit-offset pagination in a GraphQL API using query arguments with Ruby GraphQL server.

Go to next chapter