Skip to content

Commit 423adb3

Browse files
committed
fix(graphql): Allow list of errors as payloads for graphql-transport-ws subprotocol's error message type. Add tests
1 parent 1845f40 commit 423adb3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/graphql/test/websocket_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,47 @@ Future<void> main() async {
7070
});
7171
});
7272

73+
group('GraphQLSocketMessage.parse', () {
74+
test('graphql-transport-ws subprotocol with errors', () {
75+
const payload = [
76+
{
77+
'message': 'Cannot query field "wrongQuery" on type "Query".',
78+
'locations': [
79+
{'line': 1, 'column': 2}
80+
],
81+
'extensions': {
82+
'validationError': {
83+
'spec': 'https://spec.graphql.org/draft/#sec-Field-Selections',
84+
}
85+
}
86+
}
87+
];
88+
89+
const message = {'id': 'message-id', 'type': 'error', 'payload': payload};
90+
final parsed = GraphQLSocketMessage.parse(jsonEncode(message));
91+
expect(parsed, isA<SubscriptionError>());
92+
expect(parsed.toJson(), message);
93+
});
94+
95+
test('graphql-ws apollo subprotocol with errors', () {
96+
const payload = {
97+
'message': 'Cannot query field "wrongQuery" on type "Query".',
98+
'locations': [
99+
{'line': 1, 'column': 2}
100+
],
101+
'extensions': {
102+
'validationError': {
103+
'spec': 'https://spec.graphql.org/draft/#sec-Field-Selections',
104+
}
105+
}
106+
};
107+
const message = {'id': 'message-id', 'type': 'error', 'payload': payload};
108+
final parsed = GraphQLSocketMessage.parse(jsonEncode(message));
109+
expect(parsed, isA<SubscriptionError>());
110+
expect(parsed.toJson(), message);
111+
});
112+
});
113+
73114
group('SocketClient without payload', () {
74115
late SocketClient socketClient;
75116
StreamController<dynamic> controller;

0 commit comments

Comments
 (0)