Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/graphql/backtrace/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ def rows

if ast_node
field_defn = query.get_field(result.graphql_result_type, ast_node.name)
args = query.arguments_for(ast_node, field_defn).to_h
args = begin
if (cached_args = query.arguments_cache.cached_arguments_for(ast_node, field_defn))
cached_args.to_h
else
EmptyObjects::EMPTY_HASH
end
rescue StandardError => err
"Failed to load arguments, #{err.class}: #{err.message}"
end

field_path = field_defn.path
if ast_node.alias
field_path += " as #{ast_node.alias}"
Expand Down
3 changes: 3 additions & 0 deletions lib/graphql/execution/interpreter/arguments_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def fetch(ast_node, argument_owner, parent_object)
@storage[argument_owner][parent_object][ast_node] = resolved_args
end
end
end

def cached_arguments_for(ast_node, argument_owner)
@storage[argument_owner][nil][ast_node]
end

# @yield [Interpreter::Arguments, Lazy<Interpreter::Arguments>] The finally-loaded arguments
Expand Down
40 changes: 40 additions & 0 deletions spec/graphql/backtrace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,44 @@ def greeting(name:)
assert_equal ["name is too short (minimum is 5)"], ValidatorBacktraceSchema.execute("{ greeting(name: \"Tim\") }")["errors"].map { |e| e["message"] }
end
end


describe "when prepare fails as in https://github.com/rmosolgo/graphql-ruby/issues/5627" do
class BacktracePrepareErrorSchema < GraphQL::Schema
class CreateComment < GraphQL::Schema::RelayClassicMutation
argument :author_id, String, as: :author, prepare: :prepare_author
argument :body, String

field :comment_id, String

def self.prepare_author(id, _ctx)
raise "Author #{id} not found"
end

def resolve(author:, body:)
{ comment_id: "new-comment" }
end
end

class Mutation < GraphQL::Schema::Object
field :create_comment, mutation: CreateComment
end

use GraphQL::Backtrace
mutation Mutation
end

it "works" do
skip_with_exec_next
assert_raises GraphQL::Backtrace::TracedError do
BacktracePrepareErrorSchema.execute <<~GRAPHQL
mutation {
createComment(input: { authorId: "unknown", body: "hello" }) {
commentId
}
}
GRAPHQL
end
end
end
end