-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix current_depth
method
#4386
Fix current_depth
method
#4386
Conversation
Under some circumstances, the `thread_info` object is empty, and there is no result. In such case, the method should return depth 1 instead of failing.
Hey, thanks for submitting this fix! I'm interested in including a test for this case to make sure I don't break it again in the future. Could you add a test case to this PR for it, or else share the stack trace of the error you encountered? (The stack trace would likely include enough info to replicate the bug.) |
@rmosolgo I would absolutely add a failing spec, but I honestly don't know what causes it. We use FWIW, here is a stacktrace from the spec:
|
Ok, thanks, this helps -- it looks like it was resolving a list at the time. As for returning |
This is the minimum query that causes the failure in our spec: {
result: projectById(id: "#{project_id}") {
feasibilityReviews {
id
}
}
} I tried reproducing it by creating a stripped-down schema that uses the same loader and The loader used for this field looks like this: class RelationLoader < ::GraphQL::Batch::Loader
def initialize(relation:, column:)
super()
@relation = relation
@column = column
end
def perform(ids)
@relation.where(@column => ids).group_by(&@column).each do |id, records|
fulfill(id, records)
end
ids.each { |id| fulfill(id, []) unless fulfilled?(*id) }
end
end and it is used more or less like this: class ProjectType < GraphQL::Schema::Object
field :feasibility_reviews, [FeasibilityReviewType], null: false
def feasibility_reviews
RelationLoader.for(relation: Models::FeasibilityReview.where(reviewer_id: current_user.id), column: :project_id)
end
end |
Thanks for those details -- that's really helpful. I'll try to come up with a replication. Also, does |
It uses a regular ActiveRecord |
Cool, thanks for confirming. I can't figure out exactly what's wrong 😖 But I just pushed an alternative solution which simplifies the class a bit (by removing a method). Could you give that solution a try and see if it still fixes it for you, or if you still encounter an error (please share the message and backtrace if so)? |
Thank you @rmosolgo! I ran the specs and the fix works. |
Ok, thanks for checking into it. I'm afraid there's some other bug lurking here where some of the runtime context isn't set correctly 😖 But this will have to do for now. |
Under some circumstances, the
thread_info
object is empty, and there is no result. In such a case, the method should return depth 1 instead of failing.We ran into this problem after updating to
graphql
version2.0.19
(although it also happens in2.0.18
).