tstor/ui/lib/api/client.dart

48 lines
1.2 KiB
Dart
Raw Normal View History

2024-04-24 17:36:33 +00:00
import 'package:flutter/foundation.dart';
import 'package:graphql/client.dart';
// final client = GraphQLClient(
2024-04-27 11:00:34 +00:00
// link: _loggerLink.concat(HttpLink("http://localhost:4444/graphql")),
2024-04-24 17:36:33 +00:00
// cache: GraphQLCache(store: null),
// defaultPolicies: DefaultPolicies(
// query: Policies(
// fetch: FetchPolicy.noCache,
// ),
// ),
// );
2024-04-27 11:00:34 +00:00
final client = GraphQLClient(
link: HttpLink("http://192.168.217.150:4444/graphql"),
cache: GraphQLCache(store: null),
defaultPolicies: DefaultPolicies(
query: Policies(
fetch: FetchPolicy.noCache,
),
),
);
2024-04-24 17:36:33 +00:00
class LoggerLink extends Link {
@override
Stream<Response> request(
Request request, [
NextLink? forward,
]) {
Stream<Response> response = forward!(request).map((Response fetchResult) {
final ioStreamedResponse = fetchResult.context.entry<HttpLinkResponseContext>();
if (kDebugMode) {
print("Request: ${request.toString()}");
print("Response:${ioStreamedResponse?.toString() ?? "null"}");
}
return fetchResult;
}).handleError((error) {
throw error;
});
return response;
}
LoggerLink();
}
final _loggerLink = LoggerLink();