createMutation<DataType, ErrorType, VariablesType> method

Mutation<DataType, ErrorType, VariablesType> createMutation<DataType, ErrorType, VariablesType>(
  1. String key,
  2. MutationFn<DataType, VariablesType> mutationFn, {
  3. RetryConfig? retryConfig,
})

Creates a new Mutation

If a Mutation with the same key already exists, it'll return the existing Mutation and update the properties of the existing Mutation

Implementation

Mutation<DataType, ErrorType, VariablesType>
    createMutation<DataType, ErrorType, VariablesType>(
  String key,
  MutationFn<DataType, VariablesType> mutationFn, {
  RetryConfig? retryConfig,
}) {
  final mutation = cache.mutations
      .firstWhere(
        (query) => query.key == key,
        orElse: () => Mutation<DataType, ErrorType, VariablesType>(
          key,
          mutationFn,
          retryConfig: retryConfig ?? this.retryConfig,
        ),
      )
      .cast<DataType, ErrorType, VariablesType>();

  mutation.updateMutationFn(mutationFn);
  cache.addMutation(mutation);
  return mutation;
}