Skip to content

Commit 9a1398c

Browse files
committed
test(GraphQL::Backtrace) test analyzer errors
1 parent 1fd0df3 commit 9a1398c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

spec/graphql/backtrace_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def raise_err
1616
end
1717
end
1818

19+
class ErrorAnalyzer
20+
def call(_memo, visit_type, irep_node)
21+
if irep_node.name == "raiseError"
22+
raise GraphQL::AnalysisError, "this should not be wrapped by a backtrace, but instead, returned to the client"
23+
end
24+
end
25+
end
26+
1927
let(:resolvers) {
2028
{
2129
"Query" => {
@@ -49,6 +57,7 @@ def raise_err
4957
GRAPHQL
5058
GraphQL::Schema.from_definition(defn, default_resolve: resolvers).redefine {
5159
lazy_resolve(LazyError, :raise_err)
60+
query_analyzer(ErrorAnalyzer.new)
5261
}
5362
}
5463

@@ -103,7 +112,7 @@ def raise_err
103112
assert_includes err.message, rendered_table
104113
# The message includes the original error message
105114
assert_includes err.message, "This is broken: Boom"
106-
assert_includes err.message, "spec/graphql/backtrace_spec.rb:27", "It includes the original backtrace"
115+
assert_includes err.message, "spec/graphql/backtrace_spec.rb:35", "It includes the original backtrace"
107116
assert_includes err.message, "more lines"
108117
end
109118

@@ -133,6 +142,11 @@ def raise_err
133142
].join("\n")
134143
assert_includes err.message, rendered_table
135144
end
145+
146+
it "returns analysis errors to the client" do
147+
res = schema.execute("query raiseError { __typename }")
148+
assert_equal "this should not be wrapped by a backtrace, but instead, returned to the client", res["errors"].first["message"]
149+
end
136150
end
137151

138152
# This will get brittle when execution code moves between files

0 commit comments

Comments
 (0)