request method

  1. @override
Future<Map> request(
  1. JsonQuery query, {
  2. TransactionHeaders? headers,
  3. Transaction? transaction,
})
override

Sends a request to the engine.

  • query is the query to be sent to the engine.
  • headers are the headers to be sent with the request.
  • transaction is the transaction to be used for the request.

Implementation

@override
Future<Map> request(
  JsonQuery query, {
  TransactionHeaders? headers,
  Transaction? transaction,
}) async {
  headers ??= TransactionHeaders();
  await start();

  if (transaction != null) {
    headers.set('x-transaction-id', transaction.id);
  }

  final response = await fetch(
    _endpoint,
    headers: headers,
    body: query.toJson(),
    method: 'POST',
  );

  final result = await response.json();

  return switch (result) {
    {'data': final Map data} => deserializeJsonResponse(data),
    {'errors': final Iterable errors} => throwErrors(errors),
    _ => throw PrismaClientUnknownRequestError(
        message: json.encode(PrismaClientUnknownRequestError),
      ),
  };
}