Introducing GraphQL Cache

At StackShare, we’ve been experimenting with GraphQL for some of our new features. We’re using Apollo on the front end and GraphQL Ruby on the back end. Don’t worry, we’ll be publishing a full retrospective on why we chose GraphQL and how it is implemented soon.
We’ve encountered a couple of gaps in the Ruby GraphQL implementation. One of the biggest pieces missing from the gem is a clean means of implementing caching of resolved fields. GraphQL queries can get complicated - so much so that we have concepts like “max complexity” in our schema.
Of course you can implement it easy enough:
< 1.8
field :my_field, types.Int do
resolve ->(obj, args, ctx) {
Rails.cache.fetch([obj.id, 'my_field']) do
# ... some long running calculation
end
}
end
> 1.8