All Projects → nettofarah → Graphql Query Resolver

nettofarah / Graphql Query Resolver

Licence: mit
Minimize N+1 queries generated by GraphQL and ActiveRecord

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Graphql Query Resolver

Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (-32.43%)
Mutual labels:  graphql, activerecord, rails
Rails
Ruby on Rails
Stars: ✭ 49,693 (+33476.35%)
Mutual labels:  activerecord, rails
Counter culture
Turbo-charged counter caches for your Rails app.
Stars: ✭ 1,397 (+843.92%)
Mutual labels:  activerecord, rails
Spree
Open Source headless multi-language/multi-currency/multi-store eCommerce platform
Stars: ✭ 11,571 (+7718.24%)
Mutual labels:  graphql, rails
Active record replica
Redirect ActiveRecord (Rails) reads to replica databases while ensuring all writes go to the primary database.
Stars: ✭ 96 (-35.14%)
Mutual labels:  activerecord, rails
Activerecord Clean Db Structure
Automatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)
Stars: ✭ 101 (-31.76%)
Mutual labels:  activerecord, rails
Active hash relation
ActiveHash Relation: Simple gem that allows you to run multiple ActiveRecord::Relation using hash. Perfect for APIs.
Stars: ✭ 115 (-22.3%)
Mutual labels:  activerecord, rails
Chaskiq
A full featured Live Chat, Support & Marketing platform, alternative to Intercom, Drift, Crisp, etc ...
Stars: ✭ 1,263 (+753.38%)
Mutual labels:  graphql, rails
Calculate All
calculate_all method for aggregate functions in Active Record
Stars: ✭ 118 (-20.27%)
Mutual labels:  activerecord, rails
Closure tree
Easily and efficiently make your ActiveRecord models support hierarchies
Stars: ✭ 1,665 (+1025%)
Mutual labels:  activerecord, rails
Apollo upload server Ruby
Stars: ✭ 124 (-16.22%)
Mutual labels:  graphql, rails
Validates timeliness
Date and time validation plugin for ActiveModel and Rails. Supports multiple ORMs and allows custom date/time formats.
Stars: ✭ 1,319 (+791.22%)
Mutual labels:  activerecord, rails
Smart sms
The easiest way to integrate SMS service in China
Stars: ✭ 92 (-37.84%)
Mutual labels:  activerecord, rails
Rails or
Cleaner syntax for writing OR Query in Rails 5, 6. And also add #or support to Rails 3 and 4.
Stars: ✭ 86 (-41.89%)
Mutual labels:  activerecord, rails
Torque Postgresql
Add support to complex resources of PostgreSQL, like data types, array associations, and auxiliary statements (CTE)
Stars: ✭ 130 (-12.16%)
Mutual labels:  activerecord, rails
Active record Events
Manage timestamps in ActiveRecord models
Stars: ✭ 109 (-26.35%)
Mutual labels:  activerecord, rails
Pluck all
A more efficient way to get data from database. Like #pluck method but return array of hashes instead.
Stars: ✭ 83 (-43.92%)
Mutual labels:  activerecord, rails
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+754.05%)
Mutual labels:  graphql, rails
Where Or
Where or function backport from Rails 5 for Rails 4.2
Stars: ✭ 116 (-21.62%)
Mutual labels:  activerecord, rails
Activerecord where assoc
Make ActiveRecord do conditions on your associations
Stars: ✭ 126 (-14.86%)
Mutual labels:  activerecord, rails

GraphQL::QueryResolver

Build Status

GraphQL::QueryResolver is an add-on to graphql-ruby that allows your field resolvers to minimize N+1 SELECTS issued by ActiveRecord.

GraphQL::QueryResolver will analyze the AST from incoming GraphQL queries and try to match query selections to ActiveRecord::Reflections present in your ActiveRecord models.

Every matched selection will be then passed on to ActiveRecord::Associations::Preloader.new so your queries now only issue one SELECT statement for every level of the GraphQL AST.

Installation

Add this line to your application's Gemfile:

gem 'graphql-query-resolver'

And then execute:

$ bundle

Or install it yourself as:

$ gem install graphql-query-resolver

Usage

require 'graphql/query_resolver'

# In your field resolver
# Assuming `Project < ActiveRecord::Base` and a `ProjectType` GraphQL type:
#
field :projects do
  type types[ProjectType]

  resolve -> (obj, args, ctx) {
    # Wrap your field resolve operation with `GraphQL::QueryResolver`
    GraphQL::QueryResolver.run(Project, ctx, ProjectType) do
      Project.all
    end
  }
end

# QueryResolver works the same way for single objects

field :comment do
  type CommentType
  argument :id, !types.ID

  resolve -> (obj, args, ctx) {
    GraphQL::QueryResolver.run(Comment, ctx, CommentType) do
      Comment.find(args['id'])
    end
  }
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nettofarah/graphql-query-resolver. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

To run the specs across all supported versions of ActiveRecord, check out the repo and follow these steps:

$ bundle install
$ bundle exec appraisal install
$ bundle exec appraisal rake

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].