You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if this is a bug or just a dumb question, but let me explain it 😄
Starting with this simple type:
class Types::ProjectType < Types::BaseNode
graphql_name 'Project'
field :title, String, null: false
field :milestones, Types::MilestoneType.connection_type, null: false
def milestones
object.milestones
end
end
Milestone Load (0.9ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 1]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 2]]
Milestone Load (0.7ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 3]]
Milestone Load (0.6ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 4]]
Milestone Load (0.6ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 5]]
Milestone Load (0.7ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 6]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 7]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 8]]
Milestone Load (0.8ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 9]]
Milestone Load (0.8ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 10]]
So I thought it would be good to use the AssociationLoader to eager load the milestones using this:
def milestones
Loaders::AssociationLoader.for(Project, :milestones).load(object)
end
But this ends up in this:
Milestone Load (0.7ms) SELECT "milestones".* FROM "milestones" WHERE "milestones"."project_id" IN ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) [["project_id", 1], ["project_id", 2], ["project_id", 3], ["project_id", 4], ["project_id", 5], ["project_id", 6], ["project_id", 7], ["project_id", 8], ["project_id", 9], ["project_id", 10]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 1]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 2]]
Milestone Load (0.4ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 3]]
Milestone Load (0.7ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 4]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 5]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 6]]
Milestone Load (1.0ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 7]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 8]]
Milestone Load (0.5ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 9]]
Milestone Load (0.6ms) SELECT milestones.*, milestones.id AS cursor_0 FROM "milestones" WHERE "milestones"."project_id" = $1 ORDER BY milestones.id asc [["project_id", 10]]
Completed 200 OK in 497ms (Views: 0.4ms | ActiveRecord: 34.6ms)
user: peter_goebel
POST /graphql
AVOID eager loading detected
Project => [:milestones]
Remove from your finder: :includes => [:milestones]
Call stack
Why are all milestones still queried individually even with eager loading/preloading?
The text was updated successfully, but these errors were encountered:
I don't know if this is a bug or just a dumb question, but let me explain it 😄
Starting with this simple type:
And running this query:
Returns the desired result, but leads to this:
So I thought it would be good to use the AssociationLoader to eager load the milestones using this:
But this ends up in this:
Why are all milestones still queried individually even with eager loading/preloading?
The text was updated successfully, but these errors were encountered: