website/versioned_docs/version-v20.1.0/api-reference/relay-runtime/commit-mutation.md
import DocsRating from '@site/src/core/DocsRating'; import {OssOnly, FbInternalOnly} from 'docusaurus-plugin-internaldocs-fb/internal'; import MutationConfig from '../types/MutationConfig.md'; import Disposable from '../types/Disposable.md';
commitMutationImperatively execute a mutation.
See also the useMutation API and Guide to Updating Data.
import type {FeedbackLikeMutation} from 'FeedbackLikeMutation.graphql';
const React = require('React');
const {graphql, commitMutation} = require('react-relay');
function likeFeedback(environment: IEnvironment): Disposable {
return commitMutation<FeedbackLikeMutation>(environment, {
mutation: graphql`
mutation FeedbackLikeMutation($input: FeedbackLikeData!) {
feedback_like(data: $input) {
feedback {
id
viewer_does_like
like_count
}
}
}
`,
variables: {
input: {
id: '123',
},
},
});
}
environment: IEnvironment. A Relay environment.config: MutationConfig<TMutation>.Disposable which:
onComplete and onError callbacks from being executed. It will not necessarily cancel any network request. Will cause the onUnsubscribe callback to be called.