execute<T, U extends JsonSerializable> method

Future<GraphQLResponse<T>> execute<T, U extends JsonSerializable>(
  1. GraphQLQuery<T, U> query, {
  2. Context context = const Context(),
})

Executes a GraphQLQuery, returning a typed response.

Implementation

Future<GraphQLResponse<T>> execute<T, U extends JsonSerializable>(
  GraphQLQuery<T, U> query, {
  Context context = const Context(),
}) async {
  final request = Request(
    operation: Operation(
      document: query.document,
      operationName: query.operationName,
    ),
    variables: query.getVariablesMap(),
    context: context,
  );

  final response = await _link.request(request).first;

  return GraphQLResponse<T>(
    data: response.data == null ? null : query.parse(response.data ?? {}),
    errors: response.errors,
    context: response.context,
  );
}