@@ -36,10 +36,13 @@ def is_a_class_and_is_a_subclass_of_exception():
36
36
assert isinstance (GraphQLError ("str" ), Exception )
37
37
assert isinstance (GraphQLError ("str" ), GraphQLError )
38
38
39
- def has_a_name_message_and_stack_trace ():
39
+ def has_a_name_message_extensions_and_stack_trace ():
40
40
e = GraphQLError ("msg" )
41
41
assert e .__class__ .__name__ == "GraphQLError"
42
42
assert e .message == "msg"
43
+ assert e .extensions == {}
44
+ assert e .__traceback__ is None
45
+ assert str (e ) == "msg"
43
46
44
47
def uses_the_stack_of_an_original_error ():
45
48
try :
@@ -126,18 +129,27 @@ def converts_source_and_positions_to_locations():
126
129
assert e .positions == [6 ]
127
130
assert e .locations == [(2 , 5 )]
128
131
129
- def serializes_to_include_message ():
130
- e = GraphQLError ("msg" )
131
- assert str (e ) == "msg"
132
- assert repr (e ) == "GraphQLError('msg')"
133
-
134
- def serializes_to_include_message_and_locations ():
135
- e = GraphQLError ("msg" , field_node )
136
- assert "msg" in str (e )
137
- assert ":2:3" in str (e )
138
- assert repr (e ) == (
139
- "GraphQLError('msg', locations=[SourceLocation(line=2, column=3)])"
132
+ def serializes_to_include_all_standard_fields ():
133
+ e_short = GraphQLError ("msg" )
134
+ assert str (e_short ) == "msg"
135
+ assert repr (e_short ) == "GraphQLError('msg')"
136
+
137
+ path : List [Union [str , int ]] = ["path" , 2 , "field" ]
138
+ extensions = {"foo" : "bar " }
139
+ e_full = GraphQLError ("msg" , field_node , None , None , path , None , extensions )
140
+ assert str (e_full ) == (
141
+ "msg\n \n GraphQL request:2:3\n " "1 | {\n 2 | field\n | ^\n 3 | }"
142
+ )
143
+ assert repr (e_full ) == (
144
+ "GraphQLError('msg', locations=[SourceLocation(line=2, column=3)],"
145
+ " path=['path', 2, 'field'], extensions={'foo': 'bar '})"
140
146
)
147
+ assert e_full .formatted == {
148
+ "message" : "msg" ,
149
+ "locations" : [{"line" : 2 , "column" : 3 }],
150
+ "path" : ["path" , 2 , "field" ],
151
+ "extensions" : {"foo" : "bar " },
152
+ }
141
153
142
154
def repr_includes_extensions ():
143
155
e = GraphQLError ("msg" , extensions = {"foo" : "bar" })
0 commit comments