Skip to content

Commit 3fa1aea

Browse files
dehypnosisvincenzopalazzo
authored andcommitted
Merge branch 'zino-hofmann:main' into patch-2
2 parents b290073 + 360616d commit 3fa1aea

File tree

10 files changed

+115
-15
lines changed

10 files changed

+115
-15
lines changed

.github/workflows/packages_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
release:
55
types: [created]
66
tags:
7-
- v-*
7+
- v-packages-*
88
jobs:
99
publishing_client:
1010
runs-on: ubuntu-latest

packages/graphql/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v5.1.2-beta.3
2+
3+
## Fixes
4+
- Transform nested objects ([commit](https://github.com/zino-hofmann/graphql-flutter/commit/92e495dacc5f7c23a648a4053ee1bd73fb9b924e)). @budde377 27-06-2022
5+
- send connection_init message during handshake ([commit](https://github.com/zino-hofmann/graphql-flutter/commit/e1b7f821d4727f70e64dd334e45f6c65a063adfd)). @othorin 20-05-2022
6+
7+
18
# v5.1.2-beta.2
29

310
## New Feature

packages/graphql/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,20 @@ final HttpLink _httpLink = HttpLink(
907907
final Link _link = _apqLink.concat(_httpLink);
908908
```
909909

910+
## Q&A
911+
### CSRF Error while uploading MultipartFile
912+
If you are receiving csrf error from your apollo graphql server while uploading file,
913+
your need to add some additional headers to the `HttpLink`:
914+
<br>
915+
Also ensure that you're add `contentType` to `MultipartFile` as `MediaType`
916+
917+
```dart
918+
HttpLink httpLink = HttpLink('https://api.url/graphql', defaultHeaders: {
919+
'Content-Type': 'application/json; charset=utf-8',
920+
'X-Apollo-Operation-Name': 'post'
921+
})
922+
```
923+
910924
[build-status-badge]: https://img.shields.io/github/workflow/status/zino-hofmann/graphql-flutter/graphql-flutter%20Tests%20case?style=flat-square
911925
[build-status-link]: https://github.com/zino-hofmann/graphql-flutter/actions
912926
[coverage-badge]: https://img.shields.io/codecov/c/github/zino-hofmann/graphql-flutter/beta?style=flat-square

packages/graphql/changelog.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"package_name": "graphql",
3-
"version": "v5.1.2-beta.2",
3+
"version": "v5.1.2-beta.3",
44
"api": {
55
"name": "github",
66
"repository": "zino-hofmann/graphql-flutter",

packages/graphql/lib/src/cache/hive_store.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ import 'package:hive/hive.dart';
55

66
import './store.dart';
77

8+
Map<String, dynamic> _transformMap(Map<dynamic, dynamic> map) =>
9+
Map<String, dynamic>.from(
10+
{
11+
for (var entry in map.entries) entry.key: _transformAny(entry.value),
12+
},
13+
);
14+
15+
dynamic _transformAny(dynamic object) {
16+
if (object is Map) {
17+
return _transformMap(object);
18+
}
19+
if (object is List) {
20+
return _transformList(object);
21+
}
22+
return object;
23+
}
24+
25+
List<dynamic> _transformList(List<dynamic> list) => List<dynamic>.from(
26+
[
27+
for (var element in list) _transformAny(element),
28+
],
29+
);
30+
831
@immutable
932
class HiveStore extends Store {
1033
/// Default box name for the `graphql/client.dart` cache store (`graphqlClientStore`)
@@ -50,7 +73,7 @@ class HiveStore extends Store {
5073
Map<String, dynamic>? get(String dataId) {
5174
final result = box.get(dataId);
5275
if (result == null) return null;
53-
return Map<String, dynamic>.from(result);
76+
return _transformMap(result);
5477
}
5578

5679
@override

packages/graphql/lib/src/links/websocket_link/websocket_client.dart

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,37 @@ class SocketClientConfig {
141141
}
142142
}
143143

144+
/// All the protocol supported by the library
145+
@Deprecated(
146+
"`SocketSubProtocol`is deprecated and will be removed in the version 5.2.0, consider to use `GraphQLProtocol`")
144147
class SocketSubProtocol {
145148
SocketSubProtocol._();
146149

150+
/// graphql-ws: The new (not to be confused with the graphql-ws library).
151+
/// NB. This protocol is it no longer maintained, please consider
152+
/// to use `SocketSubProtocol.graphqlTransportWs`.
153+
static const String graphqlWs = GraphQLProtocol.graphqlWs;
154+
155+
/// graphql-transport-ws: New ws protocol used by most Apollo Server instances
156+
/// with subscriptions enabled use this library.
157+
/// N.B: not to be confused with the graphql-ws library that implement the
158+
/// old ws protocol.
159+
static const String graphqlTransportWs = GraphQLProtocol.graphqlWs;
160+
}
161+
162+
/// ALL protocol supported by the library
163+
class GraphQLProtocol {
164+
GraphQLProtocol._();
165+
166+
/// graphql-ws: The new (not to be confused with the graphql-ws library).
167+
/// NB. This protocol is it no longer maintained, please consider
168+
/// to use `SocketSubProtocol.graphqlTransportWs`.
147169
static const String graphqlWs = "graphql-ws";
170+
171+
/// graphql-transport-ws: New ws protocol used by most Apollo Server instances
172+
/// with subscriptions enabled use this library.
173+
/// N.B: not to be confused with the graphql-ws library that implement the
174+
/// old ws protocol.
148175
static const String graphqlTransportWs = "graphql-transport-ws";
149176
}
150177

@@ -159,7 +186,7 @@ class SocketSubProtocol {
159186
class SocketClient {
160187
SocketClient(
161188
this.url, {
162-
this.protocol = SocketSubProtocol.graphqlWs,
189+
this.protocol = GraphQLProtocol.graphqlWs,
163190
this.config = const SocketClientConfig(),
164191
@visibleForTesting this.randomBytesForUuid,
165192
@visibleForTesting this.onMessage,
@@ -247,14 +274,14 @@ class SocketClient {
247274
await config.connect(uri: Uri.parse(url), protocols: [protocol]);
248275
socketChannel = connection.forGraphQL();
249276

250-
if (protocol == SocketSubProtocol.graphqlTransportWs) {
277+
if (protocol == GraphQLProtocol.graphqlTransportWs) {
251278
_connectionStateController.add(SocketConnectionState.handshake);
252279
} else {
253280
_connectionStateController.add(SocketConnectionState.connected);
254281
}
255282
print('Initialising connection');
256283
_write(initOperation);
257-
if (protocol == SocketSubProtocol.graphqlTransportWs) {
284+
if (protocol == GraphQLProtocol.graphqlTransportWs) {
258285
// wait for ack
259286
// this blocks to prevent ping from being called before ack is recieved
260287
await _messages.firstWhere(
@@ -263,10 +290,10 @@ class SocketClient {
263290
}
264291

265292
if (config.inactivityTimeout != null) {
266-
if (protocol == SocketSubProtocol.graphqlWs) {
293+
if (protocol == GraphQLProtocol.graphqlWs) {
267294
_disconnectOnKeepAliveTimeout(_messages);
268295
}
269-
if (protocol == SocketSubProtocol.graphqlTransportWs) {
296+
if (protocol == GraphQLProtocol.graphqlTransportWs) {
270297
_enqueuePing();
271298
}
272299
}
@@ -277,7 +304,7 @@ class SocketClient {
277304
onMessage!(message);
278305
}
279306

280-
if (protocol == SocketSubProtocol.graphqlTransportWs) {
307+
if (protocol == GraphQLProtocol.graphqlTransportWs) {
281308
if (message.type == 'ping') {
282309
_write(PongMessage());
283310
} else if (message.type == 'pong') {
@@ -494,7 +521,7 @@ class SocketClient {
494521
id,
495522
serialize(payload),
496523
);
497-
if (protocol == SocketSubProtocol.graphqlTransportWs) {
524+
if (protocol == GraphQLProtocol.graphqlTransportWs) {
498525
operation = SubscribeOperation(
499526
id,
500527
serialize(payload),
@@ -512,7 +539,7 @@ class SocketClient {
512539
_subscriptionInitializers.remove(id);
513540

514541
sub?.cancel();
515-
if (protocol == SocketSubProtocol.graphqlWs &&
542+
if (protocol == GraphQLProtocol.graphqlWs &&
516543
_connectionStateController.value == SocketConnectionState.connected &&
517544
socketChannel != null) {
518545
_write(StopOperation(id));

packages/graphql/lib/src/links/websocket_link/websocket_link.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WebSocketLink extends Link {
1616
WebSocketLink(
1717
this.url, {
1818
this.config = const SocketClientConfig(),
19-
this.subProtocol = SocketSubProtocol.graphqlWs,
19+
this.subProtocol = GraphQLProtocol.graphqlWs,
2020
});
2121

2222
final String url;

packages/graphql/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: graphql
22
description: A stand-alone GraphQL client for Dart, bringing all the features from a modern GraphQL client to one easy to use package.
3-
version: 5.1.2-beta.2
3+
version: 5.1.2-beta.3
44
homepage: https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql
55

66
dependencies:

packages/graphql/test/cache/store_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,35 @@ void main() {
9292
expect(readData2, equals({'foo': 'bar'}));
9393
expect(readData2, isA<Map<String, dynamic>>());
9494
});
95+
test("Can re-open and read nested data", () async {
96+
final box1 = await HiveStore.openBox(
97+
're-open-store',
98+
path: path,
99+
);
100+
final store = HiveStore(box1);
101+
final data = {
102+
'foo': 'bar',
103+
'bob': [
104+
{'nested': true}
105+
]
106+
};
107+
store.put("id", data);
108+
final readData = await store.get("id");
109+
expect(readData, equals(data));
110+
expect(readData?['bob'], isA<List<dynamic>>());
111+
expect(readData?['bob'][0], isA<Map<String, dynamic>>());
112+
await box1.close();
113+
final box2 = await HiveStore.openBox(
114+
're-open-store',
115+
path: path,
116+
);
117+
final store2 = HiveStore(box2);
118+
final readData2 = await store2.get('id');
119+
expect(readData2, equals(data));
120+
expect(readData2, isA<Map<String, dynamic>>());
121+
expect(readData2?['bob'], isA<List<dynamic>>());
122+
expect(readData2?['bob'][0], isA<Map<String, dynamic>>());
123+
});
95124
test("Can put null", () async {
96125
final box1 = await HiveStore.openBox(
97126
'put-null',

packages/graphql/test/websocket_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SocketClient getTestClient({
1818
bool autoReconnect = true,
1919
Map<String, dynamic>? customHeaders,
2020
Duration delayBetweenReconnectionAttempts = const Duration(milliseconds: 1),
21-
String protocol = SocketSubProtocol.graphqlWs,
21+
String protocol = GraphQLProtocol.graphqlWs,
2222
}) =>
2323
SocketClient(
2424
wsUrl,
@@ -340,7 +340,7 @@ Future<void> main() async {
340340
controller = StreamController(sync: true);
341341
socketClient = getTestClient(
342342
controller: controller,
343-
protocol: SocketSubProtocol.graphqlTransportWs,
343+
protocol: GraphQLProtocol.graphqlTransportWs,
344344
wsUrl: wsUrl,
345345
);
346346
}));

0 commit comments

Comments
 (0)