Skip to content
This repository was archived by the owner on Sep 24, 2019. It is now read-only.

Active record preload #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Active record preload #40

wants to merge 3 commits into from

Conversation

xuorig
Copy link
Collaborator

@xuorig xuorig commented Feb 18, 2017

@xuorig xuorig force-pushed the active-record-preload branch from ee3cc7f to 56383de Compare February 18, 2017 20:48
@cjoudrey
Copy link
Contributor

Do we still need to keep https://github.com/GraphQLAcademy/swapi-graphql-ruby/blob/56383de8409ce7a52566cf4700e66f0992770d55/app/models/graph/association_loader.rb? There might be a case where we want to preload associations and .then do other stuff, maybe?

@@ -23,8 +25,5 @@ module Graph
model = Object.const_get(gid.model_name)
Graph::FindLoader.for(model).load(gid.model_id.to_i)
end

lazy_resolve(Promise, :sync)
instrument(:query, GraphQL::Batch::Setup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your gem includes the right setup? What happens if instrument(:query, GraphQL::Batch::Setup) is included twice by accident? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does a NestedError 🤔. I've been trying to find a way to raise a useful error but since it's order dependant it's kinda hard :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if I could handle it better in the gem: use a Set instead of an Array to store instrumenters, that way a second call would do nothing.

resolve -> (person, _, _) do
Graph::AssociationLoader.for(::Person, :homeworld).load(person)
end
preloads :homeworld
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants