N+1 Queries No More

GraphQL makes a lot of the problems of REST much easier to solve. However, one of the things that actually becomes harder to solve is N+1 queries. Today we’re going to be talking about precisely how to resolve N+1 queries in rails and GraphQL. We will dive into the nitty-gritty details of how the concept of … [Read more…]

Stop Doing Hash Resolution By Hand

By default, the ruby gem for GraphQL will allow you to define your fields without a resolver so long as the object being resolved by the parent field for that type has a method with the name of the field in question. For example, if you had a Weather GraphQL type with a field defined like … [Read more…]

Shorten Your Argument List With Input Types

Before I discovered ruby, I used to be a java programmer. I have nothing against java (or java programmers), but there just tends to be something about java programmers and method calls that look something like this: buildSomethingFromThisAbstractFactoryAndSomeOtherStuffThatNobodyCanFollow(wow, there, are, really, sixteen, arguments, null, null, null, null, null, here, null null, null) Hint: if you … [Read more…]

Clean Up Your Schema With Resolvers And Functions

Once you’ve been doing GraphQL for a while, you might start to notice that you have some repetition, or that your schema is getting unruly due to large resolvers. In this post, we will explore some ways that you can trim this down and share functionality between your fields using resolver classes and GraphQL::Function. When … [Read more…]

Presenter/Decorator Pattern in GraphQL Rails

When I first got into rails, I heard the mantra “fat model, skinny controller” an awful lot. If you’ve never heard this before, the idea is that there should be very little code in your controllers, and your models should have a lot of code/logic. This always felt weird to me – isn’t one of … [Read more…]

GraphQL Connections In Rails

So you’ve been doing some GraphQL. You’ve made some fields that you can query on, maybe even a few mutations, and life is good. Early on however, you think “hmm, what if I have a large set of data that I need to return? I should probably paginate that.” So you go to your trusted … [Read more…]

Building A GraphQL API In Rails

NOTE: This is a post I originally wrote for my job at RevUnit and I’m sharing it here with permission. The original post can be found here. Here at RevUnit we build a lot of web and mobile apps for our clients. When we’re going to build a JSON API, we typically reach for REST … [Read more…]