mutate method

Future<QueryResult<Object?>> mutate(
  1. MutationOptions<Object?> options, {
  2. RawClientOptions? raw,
  3. Exception onException(
    1. Map<String, dynamic>
    )?,
})

Resolves a single mutation according to the MutationOptions specified and returns a Future which resolves with the QueryResult or throws an Exception.

If raw is non-null, then the request is immediately performed on a new GraphQLClient and without AuthorizationException handling.

Implementation

Future<QueryResult> mutate(
  MutationOptions options, {
  RawClientOptions? raw,
  Exception Function(Map<String, dynamic>)? onException,
}) async {
  final dio.Response posted = await post(
    const RequestSerializer().serializeRequest(options.asRequest),
    operationName: options.operationName,
    onException: onException,
    raw: raw,
  );

  if (posted.data['data'] == null) {
    throw GraphQlException([GraphQLError(message: posted.data.toString())]);
  }

  final QueryResult query = QueryResult(
    options: options,
    source: QueryResultSource.network,
    data: posted.data['data'],
  );

  GraphQlProviderExceptions.fire(query, onException);
  return query;
}