@@ -24,11 +24,17 @@ def call(_memo, visit_type, irep_node)
24
24
end
25
25
end
26
26
27
+ class NilInspectObject
28
+ # Oops, this is evil, but it happens and we should handle it.
29
+ def inspect ; nil ; end
30
+ end
31
+
27
32
let ( :resolvers ) {
28
33
{
29
34
"Query" => {
30
35
"field1" => Proc . new { :something } ,
31
36
"field2" => Proc . new { :something } ,
37
+ "nilInspect" => Proc . new { NilInspectObject . new } ,
32
38
} ,
33
39
"Thing" => {
34
40
"listField" => Proc . new { :not_a_list } ,
@@ -44,6 +50,7 @@ def call(_memo, visit_type, irep_node)
44
50
type Query {
45
51
field1: Thing
46
52
field2: OtherThing
53
+ nilInspect: Thing
47
54
}
48
55
49
56
type Thing {
@@ -112,7 +119,7 @@ def call(_memo, visit_type, irep_node)
112
119
assert_includes err . message , rendered_table
113
120
# The message includes the original error message
114
121
assert_includes err . message , "This is broken: Boom"
115
- assert_includes err . message , "spec/graphql/backtrace_spec.rb:35 " , "It includes the original backtrace"
122
+ assert_includes err . message , "spec/graphql/backtrace_spec.rb:41 " , "It includes the original backtrace"
116
123
assert_includes err . message , "more lines"
117
124
end
118
125
@@ -147,6 +154,21 @@ def call(_memo, visit_type, irep_node)
147
154
res = schema . execute ( "query raiseError { __typename }" )
148
155
assert_equal "this should not be wrapped by a backtrace, but instead, returned to the client" , res [ "errors" ] . first [ "message" ]
149
156
end
157
+
158
+ it "always stringifies the #inspect response" do
159
+ err = assert_raises ( GraphQL ::Backtrace ::TracedError ) {
160
+ schema . execute ( "query { nilInspect { raiseField(message: \" 💥\" ) } }" )
161
+ }
162
+
163
+ rendered_table = [
164
+ 'Loc | Field | Object | Arguments | Result' ,
165
+ '1:22 | Thing.raiseField | | {"message"=>"💥"} | #<RuntimeError: This is broken: 💥>' ,
166
+ '1:9 | Query.nilInspect | nil | {} | {}' ,
167
+ '1:1 | query | nil | {} | {}' ,
168
+ ] . join ( "\n " )
169
+
170
+ assert_includes ( err . message , rendered_table )
171
+ end
150
172
end
151
173
152
174
# This will get brittle when execution code moves between files
0 commit comments