getNearestEndpoints method

Future<List<Endpoint>> getNearestEndpoints()

List the nearest endpoints nodes from the client's IP Returns a List<Endpoint> with infos

Implementation

Future<List<Endpoint>> getNearestEndpoints() async {
  const body = 'query { nearestEndpoints { ip, port } }';

  final result = await _client
      .withLogger(
        'getNearestEndpoints',
        logsActivation: logsActivation,
      )
      .query(
        QueryOptions(
          document: gql(body),
          parserFn: (json) =>
              NearestEndpointsResponseData.fromJson(json).endpoints,
        ),
      );

  if (result.exception?.linkException != null) {
    throw ArchethicConnectionException(
      result.exception!.linkException.toString(),
    );
  }

  return result.parsedData ?? [];
}