executeQuery method

Future executeQuery(
  1. Query query
)

Execute a Query the method receives a type Query value

Implementation

Future executeQuery(Query query) async {
  ///Get the query to server using hasura injection
  final usecase = sl.get<QueryToServer>();

  ///Receive a headers map
  final _headers = Map<String, String>.from(headers ?? {});

  ///If the headers from the [query] received are different from null
  ///the header map will add all the [query] headers
  if (query.headers != null) {
    _headers.addAll(query.headers!);
  }

  ///A request type request is created
  var request = Request(
    headers: _headers,
    type: RequestType.query,
    url: url,
    query: query,
  );

  ///[interceptedValue] receives the value from a [ClientResolver] request

  final interceptedValue = await _interceptorExecutor(
    ClientResolver.request(request, this),
  );

  /// if the [interceptedValue] is a [Response], returns the interceptedValue
  /// if the [interceptedValue] is a [HasuraError], returns the interceptedValue
  /// else, the request will be the [interceptedValue]
  if (interceptedValue is Response) {
    return interceptedValue;
  } else if (interceptedValue is HasuraError) {
    throw interceptedValue;
  } else {
    request = interceptedValue;
  }

  ///The [result] will receive the data from an interceptError or
  ///interceptResponse
  final result = await usecase(request: request);
  return (await result.fold(_interceptError, _interceptResponse)).data;
}