Fields with lazy results aren't resolved inside directive context
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start by running the provided TestSchema, TestLoader, WithAttribute directive, and query to reproduce the difference between value and lazyValue. Trace directive resolve and lazy field execution, then add a regression test showing both fields resolve to red while the directive scope is active.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
If you have a field that is resolved lazily, e.g. using a GraphQL::Batch::Loader, and that field is selected in a query using a directive which applies to the field, the field will be resolved outside of the directive's scope (outside of the yield of the directive's resolve).
Say you're using a gem with a class method that's given a block and that method sets/reverts a class variable before/after the block is called. Then you write a directive that passes resolve's block into that gem's class method as its block. Given a lazy field that uses the class variable, that field will be resolved using the "after" value instead of the "during" value.
Versions
graphql version: 2.3.7
rails (or other framework): N/A
other applicable versions (graphql-batch, etc): graphql-batch 0.6.0
GraphQL schema
class Attributed
class << self
attr_reader :attr
def with_attribute(attr)
previous_attr = @attr
@attr = attr
yield
ensure
@attr = previous_attr
end
end
end
class TestLoader < GraphQL::Batch::Loader
def perform(keys)
keys.each { fulfill(_1, Attributed.attr) }
end
end
class TestSchema < GraphQL::Schema
class TestQuery < GraphQL::Schema::Object
field :lazy_value, String
def lazy_value
TestLoader.for.load(nil)
end
field :value, String
def value
Attributed.attr
end
end
class WithAttribute < GraphQL::Schema::Directive
locations(GraphQL::Schema::Directive::QUERY)
def self.resolve(*, &block)
Attributed.with_attribute("red", &block)
end
end
query(TestQuery)
directives(WithAttribute)
use(GraphQL::Batch)
end
GraphQL query
query @withAttribute {
value
lazyValue
}
{
"data": {
"value": "red",
"lazyValue": nil
}
}
Steps to reproduce
Run the query above using the provided schema and classes
Expected behavior
Both value and lazyValue resolve to red
Actual behavior
lazyValue resolves to nil because it's outside of the withAttribute directive scope when it gets resolved and so Attributed.with_attributed has reverted to its previous attr value.
- Ngôn ngữ chính
- Ruby
- Star
- 5.4k
- Fork
- 1.4k
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 74
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rmosolgo/graphql-ruby
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
rmosolgo/graphql-ruby#5843 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
rmosolgo/graphql-ruby#5763 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
rmosolgo/graphql-ruby#5761 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
rmosolgo/graphql-ruby#5707 · 10 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
rmosolgo/graphql-ruby#5655 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rmosolgo/graphql-ruby
Issue tương tự
-
dependencies Difficulty: Easy Good First Issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
rubyforgood/casa#7325 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 10 ngày