import 'dart:async'; // ignore: uri_does_not_exist import 'cookie_client_stub.dart' // ignore: uri_does_not_exist if (dart.library.html) 'browser_cookie_client.dart' // ignore: uri_does_not_exist if (dart.library.io) 'io_cookie_client.dart'; import 'package:meta/meta.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:imagini/graphql/imagini_graphql.dart'; class APIProvider{ String _server, _accessToken, _refreshToken; GraphQLClient _client; HttpLink httpLink; // CookieLink cookieLink; static const String _GRAPHQL_ENDPOINT = "/query"; APIProvider({ @required String server, String accessToken, String refreshToken }) { _server = server; _accessToken = accessToken; _refreshToken = refreshToken; httpLink = HttpLink(_server + _GRAPHQL_ENDPOINT, httpClient: getCookieClient(), ); // cookieLink = CookieLink(_updateAccessToken, _updateRefreshToken); _client = GraphQLClient( cache: GraphQLCache(), link: httpLink, ); } // void _updateAccessToken(_accessToken) { // print("Updating Access Token: $_accessToken"); // this._accessToken = _accessToken; // } // void _updateRefreshToken(_refreshToken) { // print("Updating Refresh Token: $_accessToken"); // this._refreshToken = _refreshToken; // } Future login([ String username, String password, ]) async { assert( (username != null && password != null) || (_accessToken != null && _refreshToken != null) ); QueryResult response = await _client.query( QueryOptions( document: LoginQuery().document, variables: { "user": "admin", "password": "admin" }, ) ); final loginResponse = Login$Query.fromJson(response.data); print(loginResponse); return loginResponse.login; } void logout() { } Future mediaItems([ String startDate, String endDate, String albumID, List tagID, String type, // TODO: Make enum int page, ]) async { // Query: // /api/v1/MediaItems // Derive Params: // startDate: // &createdAt=>2020-10-10T10:10:10 // endDate: // &createdAt=<2020-10-10T10:10:10 // albumID: // &albumID=9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d // tagID: // &tagID=9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d,9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d // type: // &type=Photos // &type=Videos // page: // &page=4 // Returns: // { // // } return null; } Future tags([ int page ]) async { // Query: // /api/v1/Tags // Derive Params: // page: // &page=4 return null; } Future albums([ int page ]) async { // Query: // /api/v1/Albums // Derive Params: // page: // &page=4 return null; } Future me() async { return null; } void dispose() {} }