1.2.0 • Published 1 year ago

relay-commit-mutation-promise v1.2.0

Weekly downloads
430
License
MIT
Repository
github
Last release
1 year ago

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.

1.2.0

1 year ago

1.1.4

3 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

6 years ago

1.0.0

7 years ago