mutation<T> method

  1. @override
Future<GraphQLResponse<T>> mutation<T>(
  1. String mutation, {
  2. String? url,
  3. Map<String, dynamic>? variables,
  4. Map<String, String>? headers,
})
inherited

Implementation

@override
Future<GraphQLResponse<T>> mutation<T>(
  String mutation, {
  String? url,
  Map<String, dynamic>? variables,
  Map<String, String>? headers,
}) async {
  try {
    final res = await post(
      url,
      {'query': mutation, 'variables': variables},
      headers: headers,
    );

    final listError = res.body['errors'];
    if ((listError is List) && listError.isNotEmpty) {
      return GraphQLResponse<T>(
          graphQLErrors: listError
              .map((e) => GraphQLError(
                    code: e['extensions']['code']?.toString(),
                    message: e['message']?.toString(),
                  ))
              .toList());
    }
    return GraphQLResponse<T>.fromResponse(res);
  } on Exception catch (_) {
    return GraphQLResponse<T>(graphQLErrors: [
      GraphQLError(
        code: null,
        message: _.toString(),
      )
    ]);
  }
}