@kiwicom/smart-faq
Version:
55 lines (49 loc) • 1.17 kB
JavaScript
// @flow
import { commitMutation, graphql } from 'react-relay';
import createEnvironment from '../../shared/relay/environment';
import type {
CreateCommentMutationVariables,
CreateCommentMutationResponse,
} from './__generated__/CreateCommentMutation.graphql';
const mutation = graphql`
mutation CreateCommentMutation(
$articleId: Int!
$type: FAQCommentType!
$comment: String!
) {
addFAQArticleComment(
originalId: $articleId
type: $type
comment: $comment
) {
isRateLimitExhausted
}
}
`;
const createComment = ({
articleId,
type,
comment,
}: CreateCommentMutationVariables): Promise<CreateCommentMutationResponse> =>
new Promise((resolve, reject) => {
const variables = {
articleId,
type,
comment,
};
commitMutation(createEnvironment(), {
mutation,
variables,
onCompleted: (
response: CreateCommentMutationResponse,
errors: $ReadOnlyArray<Error>,
) => {
if (errors?.length) {
reject(errors[0]);
}
resolve(response);
},
onError: reject,
});
});
export default createComment;