Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: response extensions should be optional #1419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ class SubscriptionData extends GraphQLSocketMessage {
"type": type,
"data": data,
"errors": errors,
"extensions": extensions,
if (extensions != null) "extensions": extensions,
};

@override
int get hashCode => toJson().hashCode;

@override
bool operator ==(dynamic other) =>
bool operator ==(Object other) =>
other is SubscriptionData && jsonEncode(other) == jsonEncode(this);
}

Expand All @@ -288,14 +288,14 @@ class SubscriptionNext extends GraphQLSocketMessage {
"type": type,
"data": data,
"errors": errors,
"extensions": extensions,
if (extensions != null) "extensions": extensions,
};

@override
int get hashCode => toJson().hashCode;

@override
bool operator ==(dynamic other) =>
bool operator ==(Object other) =>
other is SubscriptionNext && jsonEncode(other) == jsonEncode(this);
}

Expand Down
53 changes: 53 additions & 0 deletions packages/graphql/test/websocket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,59 @@ Future<void> main() async {
),
);
});
test('subscription data with extensions', () async {
final payload = Request(
operation: Operation(document: parseString('subscription {}')),
);
final waitForConnection = true;
final subscriptionDataStream =
socketClient.subscribe(payload, waitForConnection);
await socketClient.connectionState
.where((state) => state == SocketConnectionState.connected)
.first;

// ignore: unawaited_futures
socketClient.socketChannel!.stream
.where((message) => message == expectedMessage)
.first
.then((_) {
socketClient.socketChannel!.sink.add(jsonEncode({
'type': 'data',
'id': '01020304-0506-4708-890a-0b0c0d0e0f10',
'payload': {
'data': {'foo': 'bar'},
'errors': [
{'message': 'error and data can coexist'}
],
'extensions': {'extensionKey': 'extensionValue'},
}
}));
});

await expectLater(
subscriptionDataStream,
emits(
// todo should ids be included in response context? probably '01020304-0506-4708-890a-0b0c0d0e0f10'
Response(
data: {'foo': 'bar'},
errors: [
GraphQLError(message: 'error and data can coexist'),
],
context: Context().withEntry(ResponseExtensions(<dynamic, dynamic>{
'extensionKey': 'extensionValue',
})),
response: {
"type": "data",
"data": {"foo": "bar"},
"errors": [
{"message": "error and data can coexist"}
],
"extensions": {'extensionKey': 'extensionValue'},
},
),
),
);
});
test('resubscribe', () async {
final payload = Request(
operation: Operation(document: gql('subscription {}')),
Expand Down
Loading