graphQLSend method

Future graphQLSend(
  1. String query, [
  2. dynamic variables
])

Implementation

Future<dynamic> graphQLSend(String query, [dynamic variables]) async {
  final Uri uri = Uri.parse(url + '/graphql');
  String body = jsonEncode(<String, dynamic>{'query': query, 'variables': variables}, toEncodable: (Object? item) {
    if (item is DateTime) {
      return item.toIso8601String();
    }
    return item;
  });
  final http.Response response = await client.post(uri, body: body);
  try {
    dynamic data = jsonDecode(utf8.decode(response.bodyBytes));
    if (data['error'] != null) {
      throw (Exception(data['error']));
    } else {
      return data['data'];
    }
  } catch (e) {
    // ignore: avoid_print
    print('==================== Remote response error ====================\n' + query + '\n' + body.toString() + '\n' + response.body);
    rethrow;
  }
}