4
4 Comments

GraphQL with Rails - Exposing fully queryable resources with minimal code

So we've been using GraphQL with Rails (via graphql-ruby) for quite some time now and thought it would be nice to share our approach.

The two key topics we had to solve when we did our implementation was (1) authorization with query scoping (Pundit) and (2) automatically generating resources and filters (because it gets quite manual otherwise)

We've shared our approach in the blog article below:
https://www.keypup.io/blog/graphql-the-rails-way-part-1-exposing-your-resources-for-querying

The principle is to use introspection and customer resolvers to automatically infer (Pundit) policy classes as well as generate filters based on exposed attributes (GraphQL types) and model columns.

This reduces the amount of code required to exposes resources to almost a one-liner (modulo type definition).

If you have a different approach on implementing GraphQL for Rails, I would be keen to hear about it!

on June 9, 2021
  1. 2

    This is actually a rarely good great RoR article on IH. Keep it up with GraphQL + RoR!

    1. 2

      Thanks mate. There shall be more parts!

      The next one is actually going to be about mutations. It's coming soon ;)

  2. 1

    Thanks for sharing.