Resolver#initialize argument cache misses arguments added by field extensions
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #5573 của @rmosolgo — đã đóng, không merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- ruby
- Lĩnh vực
- api, backend-api-design
Hướng nghiên cứu
Start with lib/graphql/schema/resolver.rb at the caching shown in the issue, then reproduce the FieldExtension example and inspect the resolver's argument lookup. Done means extension-added arguments appear in context.types.arguments(self.class) and context.types.argument(self.class, name), while existing resolution behavior remains intact.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When a FieldExtension adds arguments to a mutation field via apply, those arguments are not included in the @arguments_by_keyword cache built in Resolver#initialize. This means context.types.argument(mutation_class, name) returns nil for extension-added arguments, even though they are valid schema arguments on the field.
The root cause is this caching in Resolver#initialize:
@arguments_by_keyword = {}
context.types.arguments(self.class).each do |arg|
@arguments_by_keyword[arg.keyword] = arg
end
context.types.arguments(self.class) only returns arguments defined directly on the resolver class — not arguments added to the field by extensions.
Versions
graphql version: 2.5.15
rails (or other framework): Rails (version not specific to the bug)
other applicable versions: N/A
GraphQL schema
class ExtraInput < GraphQL::Schema::InputObject
argument :value, String, required: false
end
class MyExtension < GraphQL::Schema::FieldExtension
def apply
field.argument(:extra, ExtraInput, required: false)
end
end
class MyMutation < GraphQL::Schema::Mutation
argument :input, String, required: false
extension(MyExtension)
field :result, String
def resolve(input: nil, extra: nil)
# extra is received correctly at resolve time,
# but is not in @arguments_by_keyword
{ result: "ok" }
end
end
class MutationRoot < GraphQL::Schema::Object
field :my_mutation, mutation: MyMutation
end
class MySchema < GraphQL::Schema
mutation MutationRoot
end
GraphQL query
mutation {
myMutation(input: "test", extra: { value: "hello" }) {
result
}
}
Steps to reproduce
- Define a
FieldExtensionthat adds an argument viafield.argument(...)inapply - Attach the extension to a mutation with
extension(MyExtension) - In any code that runs during resolution, call
context.types.argument(MyMutation, "extra")— it returnsnil - Alternatively, inspect
@arguments_by_keywordinside the resolver —:extrais missing
Expected behavior
context.types.arguments(self.class) (and by extension context.types.argument(self.class, name)) should include arguments added by field extensions, since those arguments are part of the field's actual schema signature and are accepted at query time.
Actual behavior
Extension-added arguments are missing from @arguments_by_keyword and from context.types.argument lookups against the resolver class. The arguments work correctly at resolve time (they're passed as keyword args), but any introspection or validation code that uses the types API to look up arguments on the mutation class can't find them.
Additional context
A workaround is to look up arguments via the schema field instead of the resolver class:
mutation_root = context.schema.mutation
mutation_field = context.types.field(mutation_root, "myMutation")
context.types.argument(mutation_field, "extra") # => returns the argument
This correctly finds extension-added arguments, but requires traversing the schema manually rather than using the resolver class directly.
- 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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/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
-
account: profile
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
ysb3996-blip/oops#24 ·
Maintainer thường phản hồi trong vòng 1 ngày