Skip to content

Instantly share code, notes, and snippets.

@zeienko-vitalii
Created March 20, 2024 13:42
Show Gist options
  • Save zeienko-vitalii/d32f2609a6c4068499ac07d551172031 to your computer and use it in GitHub Desktop.
Save zeienko-vitalii/d32f2609a6c4068499ac07d551172031 to your computer and use it in GitHub Desktop.
graphql_client
import 'package:ferry/ferry.dart';
import 'package:gql_http_link/gql_http_link.dart';
import 'package:simple_articles_app/utils/logger.dart';
const String baseUrl =
'https://api-eu-central-1.graphcms.com/v2/ckl4xdv123tnhmkc/master';
class GraphQlClient {
/// Initialises [_client] with setting cache store
factory GraphQlClient() {
_client ??= Client(link: HttpLink(baseUrl));
return _singleton;
}
GraphQlClient._();
static final GraphQlClient _singleton = GraphQlClient._();
static Client? _client;
Client get client {
if (_client == null) {
debugLog('GraphQlClient.safeClient: client is null');
}
return _client!;
}
void dispose() {
debugLog('GraphQlClient.dispose');
_client?.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment