@@ -229,6 +229,59 @@ Future<void> main() async {
229
229
),
230
230
);
231
231
});
232
+ test ('subscription data with extensions' , () async {
233
+ final payload = Request (
234
+ operation: Operation (document: parseString ('subscription {}' )),
235
+ );
236
+ final waitForConnection = true ;
237
+ final subscriptionDataStream =
238
+ socketClient.subscribe (payload, waitForConnection);
239
+ await socketClient.connectionState
240
+ .where ((state) => state == SocketConnectionState .connected)
241
+ .first;
242
+
243
+ // ignore: unawaited_futures
244
+ socketClient.socketChannel! .stream
245
+ .where ((message) => message == expectedMessage)
246
+ .first
247
+ .then ((_) {
248
+ socketClient.socketChannel! .sink.add (jsonEncode ({
249
+ 'type' : 'data' ,
250
+ 'id' : '01020304-0506-4708-890a-0b0c0d0e0f10' ,
251
+ 'payload' : {
252
+ 'data' : {'foo' : 'bar' },
253
+ 'errors' : [
254
+ {'message' : 'error and data can coexist' }
255
+ ],
256
+ 'extensions' : {'extensionKey' : 'extensionValue' },
257
+ }
258
+ }));
259
+ });
260
+
261
+ await expectLater (
262
+ subscriptionDataStream,
263
+ emits (
264
+ // todo should ids be included in response context? probably '01020304-0506-4708-890a-0b0c0d0e0f10'
265
+ Response (
266
+ data: {'foo' : 'bar' },
267
+ errors: [
268
+ GraphQLError (message: 'error and data can coexist' ),
269
+ ],
270
+ context: Context ().withEntry (ResponseExtensions (< dynamic , dynamic > {
271
+ 'extensionKey' : 'extensionValue' ,
272
+ })),
273
+ response: {
274
+ "type" : "data" ,
275
+ "data" : {"foo" : "bar" },
276
+ "errors" : [
277
+ {"message" : "error and data can coexist" }
278
+ ],
279
+ "extensions" : {'extensionKey' : 'extensionValue' },
280
+ },
281
+ ),
282
+ ),
283
+ );
284
+ });
232
285
test ('resubscribe' , () async {
233
286
final payload = Request (
234
287
operation: Operation (document: gql ('subscription {}' )),
0 commit comments