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, {
'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 (err) {
return GraphQLResponse<T>(
graphQLErrors: [GraphQLError(code: null, message: err.toString())],
);
}
}