Back to Relay

commitMutation

website/versioned_docs/version-v18.0.0/api-reference/relay-runtime/commit-mutation.md

20.1.11.6 KB
Original Source

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';

commitMutation

Imperatively execute a mutation.

See also the useMutation API and Guide to Updating Data.

js
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',
      },
    },
  });
}

Arguments

<MutationConfig />

Return Value

  • A Disposable which:
    • If called while before the request completes, will cancel revert any optimistic updates and prevent the onComplete and onError callbacks from being executed. It will not necessarily cancel any network request. Will cause the onUnsubscribe callback to be called.
    • If called after the initial request completes, will do nothing.
<Disposable /> <DocsRating />