hoverinc/graphql-eager_load

Created Dec 28, 2020 · View the hoverinc/graphql-eager_load repository page

Generate ActiveRecord eager loading options from GraphQL Queries

Want this for your repo?

Render a free sample of any GitHub repo in seconds.

Visualize your own →

Contributors

2

Lines of Code

79

From

Aug 3, 2020

To

Aug 11, 2020

About hoverinc/graphql-eager_load

Graphql::EagerLoad is a Ruby gem designed to prevent N+1 query problems in Rails applications that use GraphQL and ActiveRecord. The gem analyzes GraphQL queries to automatically generate ActiveRecord eager loading options by matching GraphQL fields to their corresponding model associations. It traverses the query structure, identifies which associations are actually requested, and builds an includes hash that can be passed directly to ActiveRecord queries for efficient data loading.

The gem works through convention, assuming that GraphQL types and fields closely mirror the underlying Rails data model. It provides helper methods like `eager_load_model` and `associations_to_eager_load` that integrate directly into GraphQL resolvers. The gem offers flexibility for edge cases, including options to handle custom methods that override association fields, allow inclusion of associations that are overridden by custom resolvers, and specify derived associations that need loading even when not directly queried.

The project is maintained by Hover Inc and is distributed under the MIT license, with development managed through standard Ruby gem conventions using Bundler and Rake for testing and releases.

Share this video