rescue_from handler return values during argument coercion are passed to resolve as the argument's value
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #5837 来自 @austinjb32 —— 已合并
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 58/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- ruby
调研方向
Start in Schema::Argument#coerce_into_values and trace the three handle_or_reraise call sites, then check how coerce_arguments and Runtime#evaluate_selection_with_args handle errors. Reproduce with the provided schema and argument validation example. Done means a returned GraphQL::ExecutionError reaches the response as the expected error and the resolver does not receive it as an argument; add a regression test for that behavior.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When an error is raised during argument coercion — e.g. an argument validates: check failing inside Schema::Argument#prepare_value — the error is routed through handle_or_reraise, and the schema's rescue_from handler's return value is stored as the argument's value. If the handler returns a GraphQL::ExecutionError (a very common pattern), that error object is passed to the field's resolver as the argument value instead of short-circuiting resolution with the error.
Runtime#evaluate_selection_with_args only short-circuits when resolved_arguments itself is an ExecutionError/UnauthorizedError — errors nested inside the Arguments object sail through.
Versions
graphql 2.6.13 (also reproduced on 2.5.11)
Steps to reproduce
require "graphql"
class LeakySchema < GraphQL::Schema
# Common pattern: rescue_from returns (rather than raises) an error object
rescue_from(StandardError) do |err, _obj, _args, _ctx, _field|
GraphQL::ExecutionError.new(err.message)
end
class Query < GraphQL::Schema::Object
field :check, Integer, null: true do
argument :limit, Integer, validates: { numericality: { within: 1..50 } }
end
def check(limit:)
limit + 1
end
end
query(Query)
end
pp LeakySchema.execute("{ check(limit: 0) }").to_h
Expected behavior
{"errors" => [{"message" => "limit must be within 1..50", ...}], "data" => {"check" => nil}}
Actual behavior
resolve receives the GraphQL::ExecutionError instance as limit, so limit + 1 raises NoMethodError, which the handler then converts into a misleading error:
{"errors" => [{"message" => "undefined method '+' for an instance of GraphQL::ExecutionError", ...}]}
Without any rescue_from handler, the error reraises and surfaces correctly — so this only reproduces on schemas that register a handler which returns an error object. (It also makes the behavior environment-dependent if the handler is registered conditionally, e.g. only outside development.)
Diagnosis
Schema::Argument#coerce_into_values rescues coercion errors via context.schema.handle_or_reraise(context, err) at all three call sites (type.coerce_input, prepare_value, load_and_authorize_value) and assigns the return value as the argument value:
prepared_value = begin
prepare_value(parent_object, resolved_coerced_value, context: context)
rescue StandardError => err
context.schema.handle_or_reraise(context, err) # <= a returned error object lands here
end
coerce_arguments correctly handles raised errors (finished_args = err → continue_value), but nothing handles handler-returned ones.
Possible fix
Re-raise the handled result when it's an error object, so coerce_arguments short-circuits with it — I've got a working branch with a failing test + fix here if useful: https://github.com/austinjb32/graphql-ruby/tree/fix-argument-validation-error-leak
Additional context
Same bug family as the historical prepare:-returns-error leak (#1024).
- 主要语言
- Ruby
- 星标
- 5.4k
- 派生
- 1.4k
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 74
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rmosolgo/graphql-ruby 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
rmosolgo/graphql-ruby#5843 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 55/100
rmosolgo/graphql-ruby#5763 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
rmosolgo/graphql-ruby#5761 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 52/100
rmosolgo/graphql-ruby#5707 · 10 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 30/100
rmosolgo/graphql-ruby#5655 · 4 条评论 ·
维护者通常 1 天内回复
查看 rmosolgo/graphql-ruby 的全部 Issue
相似的 Issue
-
dependencies Difficulty: Easy Good First Issue
难度 1/5 1 小时以内 新手友好度 82/100
rubyforgood/casa#7325 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
davidteren/mutineer#364 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复