mutation<T> method
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 ?? '',
body: {'query': mutation, 'variables': variables},
header: 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(message: _.toString())],
);
}
}