Skip to content

Commit 197d3ee

Browse files
committed
Fixed NonNull ordered errors in tests
1 parent a1ecaf4 commit 197d3ee

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

graphql/execution/experimental/tests/test_nonnull.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,34 @@ def nonNullPromiseNest(self):
8181
schema = GraphQLSchema(DataType)
8282

8383

84+
def order_errors(error):
85+
locations = error['locations']
86+
return (locations[0]['column'], locations[0]['line'])
87+
88+
8489
def check(doc, data, expected):
8590
ast = parse(doc)
8691
response = execute(schema, ast, data)
8792

8893
if response.errors:
89-
9094
result = {
9195
'data': response.data,
9296
'errors': [format_error(e) for e in response.errors]
9397
}
98+
if result['errors'] != expected['errors']:
99+
assert result['data'] == expected['data']
100+
# Sometimes the fields resolves asynchronously, so
101+
# we need to check that the errors are the same, but might be
102+
# raised in a different order.
103+
assert sorted(result['errors'], key=order_errors) == sorted(expected['errors'], key=order_errors)
104+
else:
105+
assert result == expected
94106
else:
95107
result = {
96108
'data': response.data
97109
}
98110

99-
assert result == expected
111+
assert result == expected
100112

101113

102114
def test_nulls_a_nullable_field_that_throws_sync():

graphql/execution/tests/test_nonnull.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def nonNullPromiseNest(self):
8181
schema = GraphQLSchema(DataType)
8282

8383

84+
def order_errors(error):
85+
locations = error['locations']
86+
return (locations[0]['column'], locations[0]['line'])
87+
88+
8489
def check(doc, data, expected):
8590
ast = parse(doc)
8691
response = execute(schema, ast, data)
@@ -90,12 +95,20 @@ def check(doc, data, expected):
9095
'data': response.data,
9196
'errors': [format_error(e) for e in response.errors]
9297
}
98+
if result['errors'] != expected['errors']:
99+
assert result['data'] == expected['data']
100+
# Sometimes the fields resolves asynchronously, so
101+
# we need to check that the errors are the same, but might be
102+
# raised in a different order.
103+
assert sorted(result['errors'], key=order_errors) == sorted(expected['errors'], key=order_errors)
104+
else:
105+
assert result == expected
93106
else:
94107
result = {
95108
'data': response.data
96109
}
97110

98-
assert result == expected
111+
assert result == expected
99112

100113

101114
def test_nulls_a_nullable_field_that_throws_sync():

0 commit comments

Comments
 (0)