diff --git a/CHANGELOG.md b/CHANGELOG.md index 68dbfa1b6..46cb0c9a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [3.23.1] +- Fix allowSelfSigned on Flutter web + ## [3.23.0] - Add GetResponsive (@SchabanBo) - Update tests, fix predicate for offNamedUntil (@vbuberen) diff --git a/lib/get_connect/connect.dart b/lib/get_connect/connect.dart index 9baf22e6b..f6e03fc1d 100644 --- a/lib/get_connect/connect.dart +++ b/lib/get_connect/connect.dart @@ -1,5 +1,6 @@ import '../get_instance/src/lifecycle.dart'; import 'http/src/certificates/certificates.dart'; +import 'http/src/exceptions/exceptions.dart'; import 'http/src/http.dart'; import 'http/src/response/response.dart'; import 'sockets/sockets.dart'; @@ -206,14 +207,105 @@ class GetConnect extends GetConnectInterface { } @override - GetSocket socket(String url, {Duration ping = const Duration(seconds: 5)}) { + GetSocket socket( + String url, { + Duration ping = const Duration(seconds: 5), + }) { _checkIfDisposed(isHttp: false); - final _url = baseUrl == null ? url : baseUrl + url; - final _socket = GetSocket(_url, ping: ping); + + final _socket = GetSocket(_concatUrl(url), ping: ping); sockets.add(_socket); return _socket; } + String _concatUrl(String url) { + if (url == null) return baseUrl; + return baseUrl == null ? url : baseUrl + url; + } + + /// query allow made GraphQL raw querys + /// final connect = GetConnect(); + /// connect.baseUrl = 'https://countries.trevorblades.com/'; + /// final response = await connect.query( + /// r""" + /// { + /// country(code: "BR") { + /// name + /// native + /// currency + /// languages { + /// code + /// name + /// } + /// } + ///} + ///""", + ///); + ///print(response.body); + Future> query( + String query, { + String url, + Map variables, + Map headers, + }) async { + try { + final res = + await post(_concatUrl(url), {'query': query, 'variables': variables}); + + final listError = res.body['errors']; + if ((listError is List) && listError.isNotEmpty) { + // return GraphQLResponse(body: res.body['data'] as T); + return GraphQLResponse( + graphQLErrors: listError + .map((e) => GraphQLError( + code: e['extensions']['code']?.toString(), + message: e['message']?.toString(), + )) + .toList()); + } + return GraphQLResponse(body: res.body['data'] as T); + } on Exception catch (_) { + return GraphQLResponse(graphQLErrors: [ + GraphQLError( + code: null, + message: _.toString(), + ) + ]); + } + } + + Future> mutation( + String mutation, { + String url, + Map variables, + Map headers, + }) async { + try { + final res = await post( + _concatUrl(url), {'query': mutation, 'variables': variables}); + + final listError = res.body['errors']; + if ((listError is List) && listError.isNotEmpty) { + // return GraphQLResponse(body: res.body['data'] as T); + return GraphQLResponse( + graphQLErrors: listError + .map((e) => GraphQLError( + code: e['extensions']['code']?.toString(), + message: e['message']?.toString(), + )) + .toList()); + } + return GraphQLResponse(body: res.body['data'] as T); + } on Exception catch (_) { + return GraphQLResponse(graphQLErrors: [ + GraphQLError( + code: null, + message: _.toString(), + ) + ]); + } + } + bool _isDisposed = false; bool get isDisposed => _isDisposed; diff --git a/lib/get_connect/http/src/exceptions/exceptions.dart b/lib/get_connect/http/src/exceptions/exceptions.dart index 3daec28c1..fba713a5a 100644 --- a/lib/get_connect/http/src/exceptions/exceptions.dart +++ b/lib/get_connect/http/src/exceptions/exceptions.dart @@ -9,6 +9,15 @@ class GetHttpException implements Exception { String toString() => message; } +class GraphQLError { + GraphQLError({this.code, this.message}); + final String message; + final String code; + + @override + String toString() => 'GETCONNECT ERROR:\n\tcode:$code\n\tmessage:$message'; +} + class UnauthorizedException implements Exception { @override String toString() { diff --git a/lib/get_connect/http/src/response/response.dart b/lib/get_connect/http/src/response/response.dart index a08883e3d..3112317df 100644 --- a/lib/get_connect/http/src/response/response.dart +++ b/lib/get_connect/http/src/response/response.dart @@ -1,8 +1,14 @@ import 'dart:collection'; import 'dart:convert'; +import '../exceptions/exceptions.dart'; import '../request/request.dart'; import '../status/http_status.dart'; +class GraphQLResponse extends Response { + final List graphQLErrors; + GraphQLResponse({T body, this.graphQLErrors}) : super(body: body); +} + class Response { const Response({ this.request, diff --git a/pubspec.yaml b/pubspec.yaml index 7258951c6..85864d5e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: get description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with GetX. -version: 3.23.0 +version: 3.23.1 homepage: https://github.com/jonataslaw/getx environment: