Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-eager_loader

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-eager_loader

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Graphql::EagerLoader

Eager-load your Active Record associations automagically.

Usage

Call this method like this:

Graphql::EagerLoader::LookaheadLoader.call(Project, lookahead)

Here's a full example with 'graphql' field:

field :projects, Types::ProjectType, null: true, extras: [:lookahead]
def projects(lookahead:)
  Graphql::EagerLoader::LookaheadLoader.call(Project, lookahead).all # or: .where(published: true)
end

This method allows you to add additional functionality while eager loading app's models. For example you can do stuff like (notice the location of .all below):

field :projects, Types::ProjectType, null: true, extras: [:lookahead]
def projects(lookahead:)
  Graphql::EagerLoader::LookaheadLoader.call(Project, lookahead) do |eager_loaded_model, associations|
    associations.values.each do |association|
      if association.instance_of?(ActiveRecord::Reflection::HasManyReflection)
        eager_loaded_model = eager_loaded_model.merge(association.klass.where(published: true))
      end
    end
    eager_loaded_model
  end.all
end

Installation

gem 'graphql-eager_loader'

And then execute:

$ bundle install

Contributing

Contributions welcome!

Special Thanks

Thank you to @colinjfw for the great GraphQL-Api gem that inspired this.

Thank you to @rmosolgo for the incredible GraphQL gem.

License

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

FAQs

Package last updated on 01 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc