relay-commit-mutation-promise
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

relay-commit-mutation-promise

Promise wrapper for Relay Modern's commit mutation

Installation

npm install relay-commit-mutation-promise

Usage with Relay Modern

const commitMutation = require('relay-commit-mutation-promise');
const {graphql} = require('react-relay');

const mutation = graphql`
  mutation MarkReadNotificationMutation(
    $input: MarkReadNotificationData!
  ) {
    markReadNotification(data: $input) {
      notification {
        seenState
      }
    }
  }
`;
const variables = {
  input: {
    source,
    storyID,
  },
};

commitMutation(environment, {mutation, variables})
  .then(response => {
    // handle successful response
  })
  .catch(error => {
    const graphqlErrors = error.source.errors;
    // handle error
  });

Usage with Relay Modern compat layer

const commitMutation = require('relay-commit-mutation-promise/compat');

Accessing GraphQL errors

The error object returned in the rejected promise contains a source property which contains an array of the errors returned by the GraphQL server.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i relay-commit-mutation-promise

      Weekly Downloads

      1,946

      Version

      1.2.0

      License

      MIT

      Unpacked Size

      4.36 kB

      Total Files

      6

      Last publish

      Collaborators

      • robrichard