mutateList<T> method
Future<List<T>>
mutateList<
T>({ - required String mutation,
- Map<String, dynamic>? variable,
- FetchPolicy? fetchPolicy,
- required T modelParser(
- dynamic json
),
})
Implementation
Future<List<T>> mutateList<T>({
required String mutation,
Map<String, dynamic>? variable,
FetchPolicy? fetchPolicy,
required T Function(dynamic json) modelParser,
}) async {
try {
final response = await _client.mutate(
MutationOptions(
document: gql(mutation),
variables: variable ?? {},
fetchPolicy: fetchPolicy ?? _gqlConfig.mutationPolicy,
),
);
if (response.hasException) {
throw response.exception!;
}
if (response.data == null) {
return <T>[];
}
final resolvedData = _getResolvedData(mutation, response.data!);
if (resolvedData is List) {
try {
return resolvedData
.map((json) => modelParser(json))
.toList()
.cast<T>();
} catch (e, s) {
log("Model parsing error $e,\n$s");
rethrow;
}
}
return <T>[];
} catch (exception) {
throw GQLException.fromException(
exception,
exceptionProviders: _gqlConfig.exceptionProviders,
);
}
}