mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 17:26:35 +00:00
chore: Rename and unify GraphQL logging classes
This commit is contained in:
parent
813d275d12
commit
8dffcab30d
|
@ -1,6 +1,3 @@
|
||||||
// ignore_for_file: prefer_foreach
|
|
||||||
|
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:graphql_flutter/graphql_flutter.dart';
|
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||||
|
@ -17,7 +14,7 @@ void _logToAppConsole<T>(final T objectToLog) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoggingLink extends Link {
|
class RequestLoggingLink extends Link {
|
||||||
@override
|
@override
|
||||||
Stream<Response> request(
|
Stream<Response> request(
|
||||||
final Request request, [
|
final Request request, [
|
||||||
|
@ -28,7 +25,7 @@ class LoggingLink extends Link {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoggingResponseParser extends ResponseParser {
|
class ResponseLoggingParser extends ResponseParser {
|
||||||
@override
|
@override
|
||||||
Response parseResponse(final Map<String, dynamic> body) {
|
Response parseResponse(final Map<String, dynamic> body) {
|
||||||
final response = super.parseResponse(body);
|
final response = super.parseResponse(body);
|
||||||
|
@ -61,12 +58,12 @@ abstract class ApiMap {
|
||||||
final httpLink = HttpLink(
|
final httpLink = HttpLink(
|
||||||
'https://api.$rootAddress/graphql',
|
'https://api.$rootAddress/graphql',
|
||||||
httpClient: ioClient,
|
httpClient: ioClient,
|
||||||
parser: LoggingResponseParser(),
|
parser: ResponseLoggingParser(),
|
||||||
);
|
);
|
||||||
|
|
||||||
final String token = _getApiToken();
|
final String token = _getApiToken();
|
||||||
|
|
||||||
final Link graphQLLink = LoggingLink().concat(
|
final Link graphQLLink = RequestLoggingLink().concat(
|
||||||
isWithToken
|
isWithToken
|
||||||
? AuthLink(
|
? AuthLink(
|
||||||
getToken: () async =>
|
getToken: () async =>
|
||||||
|
@ -76,8 +73,8 @@ abstract class ApiMap {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Every request goes through either chain:
|
// Every request goes through either chain:
|
||||||
// 1. AuthLink -> HttpLink -> LoggingLink
|
// 1. RequestLoggingLink -> AuthLink -> HttpLink
|
||||||
// 2. HttpLink -> LoggingLink
|
// 2. RequestLoggingLink -> HttpLink
|
||||||
|
|
||||||
return GraphQLClient(
|
return GraphQLClient(
|
||||||
cache: GraphQLCache(),
|
cache: GraphQLCache(),
|
||||||
|
|
Loading…
Reference in a new issue