A query batching executor for the graphql gem that reduces N+1 queries by grouping database loads.
GraphQL::Batch is a Ruby gem that provides a batch loading executor for the graphql-ruby library. It solves the N+1 query problem in GraphQL APIs by grouping similar database requests into single queries, dramatically reducing database roundtrips and improving performance.
Ruby developers building GraphQL APIs with the graphql-ruby gem who need to optimize database queries and eliminate N+1 problems in their resolvers.
Developers choose GraphQL::Batch because it implements the DataLoader pattern specifically for graphql-ruby with minimal configuration, provides a clean promise-based API, and includes ActiveRecord integration examples for real-world use cases.
A query batching executor for the graphql gem
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Groups multiple data requests into single database queries, eliminating the N+1 problem as described in the README's basic usage with RecordLoader examples.
Allows creation of reusable loader classes with custom grouping logic, evidenced by the need to define a perform method for different data models.
Uses promise.rb for chaining and transforming results with methods like .then and Promise.all, shown in the promises section for dependent queries.
Includes examples for ActiveRecord with edge case handling, such as type casting IDs, as mentioned in the README for real-world use.
Requires writing custom loader classes for each data model, which can be boilerplate-heavy and time-consuming, as seen in the need to define initialize and perform methods.
Only works with the graphql-ruby gem, making it incompatible with other GraphQL frameworks in Ruby or other languages, as it's a plugin for that specific library.
While not dependent on ActiveRecord, the provided examples focus on it, potentially requiring additional effort for other database layers or ORMs, as acknowledged in the README.