fix(client): crashed upload file
Beside fixing the crash (close this commit also have flashing deprecation warning,
and clean up logs during test.
MODIFY
packages/graphql/dart_test.yaml
packages/graphql/dart_test.yaml
+tags:
+ integration:
+
define_platforms:
chromium:
name: Chromium

MODIFY
packages/graphql/lib/src/link/http/link_http.dart
packages/graphql/lib/src/link/http/link_http.dart
@@ -174,7 +174,7 @@ Future<BaseRequest> _prepareRequest(
// @deprecated, backward compatible only
// in case the body is io.File
// in future release, io.File will no longer be supported
- if (isIoFile(body)) {
+ if (isIoFile(object)) {
return null;
}
return object.toJson();

MODIFY
packages/graphql/lib/src/utilities/file_io.dart
packages/graphql/lib/src/utilities/file_io.dart
@@ -5,10 +5,19 @@ import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart';
import 'package:path/path.dart';
+MediaType contentType(f) {
+ final a = lookupMimeType(f.path);
+ if (a == null) {
+ return null;
+ }
+ final b = MediaType.parse(a);
+ return b;
+}
+
Future<MultipartFile> multipartFileFrom(io.File f) async => MultipartFile(
'',
f.openRead(),
await f.length(),
- contentType: MediaType.parse(lookupMimeType(f.path)),
+ contentType: contentType(f),
filename: basename(f.path),
);

MODIFY
packages/graphql/test/in_memory_storage_io_test.dart
packages/graphql/test/in_memory_storage_io_test.dart
@@ -5,6 +5,8 @@ import 'dart:io';
import 'package:test/test.dart';
import 'package:graphql/src/cache/in_memory_io.dart';
+import 'helpers.dart';
+
void main() {
group('In memory exception handling', () {
test('FileSystemException', overridePrint((List<String> log) async {
@@ -19,11 +21,3 @@ void main() {
}));
});
}
-
-overridePrint(testFn(List<String> log)) => () {
- final log = <String>[];
- final spec = new ZoneSpecification(print: (_, __, ___, String msg) {
- log.add(msg);
- });
- return Zone.current.fork(specification: spec).run(() => testFn(log));
- };

MODIFY
packages/graphql/test/socket_client_test.dart
packages/graphql/test/socket_client_test.dart
@@ -7,20 +7,22 @@ import 'package:test/test.dart';
import 'package:graphql/src/socket_client.dart'
show SocketClient, SocketConnectionState;
+import 'helpers.dart';
+
void main() {
group('SocketClient', () {
SocketClient socketClient;
- setUp(() {
+ setUp(overridePrint((log) {
socketClient = SocketClient(
'ws://echo.websocket.org',
protocols: null,
randomBytesForUuid: Uint8List.fromList(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
);
- });
- tearDown(() async {
+ }));
+ tearDown(overridePrint((log) async {
await socketClient.dispose();
- });
+ }));
test('connection', () async {
await expectLater(
socketClient.connectionState.asBroadcastStream(),

MODIFY
packages/graphql/test/websocket_legacy_io_test.dart
packages/graphql/test/websocket_legacy_io_test.dart
@@ -10,13 +10,15 @@ import 'package:graphql/src/websocket/messages.dart';
import 'package:graphql/legacy_socket_api/legacy_socket_client.dart';
+import 'helpers.dart';
+
void main() {
group(
'SocketClient',
() {
// ignore: deprecated_member_use_from_same_package
SocketClient socketClient;
- setUp(() {
+ setUp(overridePrint((log) {
// ignore: deprecated_member_use_from_same_package
socketClient = SocketClient(
'ws://echo.websocket.org',
@@ -24,10 +26,10 @@ void main() {
randomBytesForUuid: Uint8List.fromList(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
);
- });
- tearDown(() async {
+ }));
+ tearDown(overridePrint((log) async {
await socketClient.dispose();
- });
+ }));
test('connection', () async {
await expectLater(
socketClient.connectionState.asBroadcastStream(),

fix(client): crashed upload file

Beside fixing the crash (close #336), this commit also have flashing deprecation warning,
and clean up logs during test.