post<T> method

Future<Response<T>> post<T>(
  1. dynamic data, {
  2. Options? options,
  3. String? operationName,
  4. Exception onException(
    1. Map<String, dynamic>
    )?,
  5. void onSendProgress(
    1. int,
    2. int
    )?,
})

Makes an HTTP POST request with an exposed onSendProgress.

Implementation

Future<dio.Response<T>> post<T>(
  dynamic data, {
  dio.Options? options,
  String? operationName,
  Exception Function(Map<String, dynamic>)? onException,
  void Function(int, int)? onSendProgress,
}) {
  return _middleware(() async {
    return await _transaction(operationName, () async {
      final dio.Options authorized = options ?? dio.Options();
      authorized.headers = (authorized.headers ?? {});
      authorized.headers!['Authorization'] = 'Bearer $token';

      try {
        return await (await PlatformUtils.dio).post<T>(
          '${Config.url}:${Config.port}${Config.graphql}',
          data: data,
          options: authorized,
          onSendProgress: onSendProgress,
        );
      } on dio.DioException catch (e) {
        if (e.response != null) {
          if (onException != null &&
              e.response?.data is Map<String, dynamic> &&
              e.response?.data['data'] != null) {
            throw onException(e.response!.data['data']);
          }
        }

        rethrow;
      }
    });
  });
}