Back to Relay

commitMutation

website/docs/api-reference/relay-runtime/commit-mutation.mdx

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.mdx'; import Disposable from '../types/Disposable.mdx';

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 before the request completes, will cancel and 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 />