performMutation method

Future<QueryResult<Object?>?> performMutation(
  1. String gqlMutation,
  2. Map<String, dynamic> variables, [
  3. String? token
])

Implementation

Future<QueryResult?> performMutation(
    String gqlMutation, Map<String, dynamic> variables,
    [String? token]) async {
  try {
    GraphQLClient _client = await getClient(token);

    QueryResult result = await _client.mutate(MutationOptions(
        document: gql(gqlMutation),
        variables: variables,
        fetchPolicy: FetchPolicy.networkOnly));

    if (result.hasException) {
      if (kDebugMode) {
        print(
            "Exception while performing mutation: ${result.exception.toString()}");
      }

      return null;
    }
    return result;
  } catch (e) {
    if (kDebugMode) {
      print("Error while performing mutation: $e");
    }

    return null;
  }
}