[next] Story Mutations (#2055)

*  feat: added mutations for removing + scraping stories

- added mutation for removing stories
- added mutation for scraping stories
- renamed all delete* to remove* to avoid reserved keyword collision

* fix: linting

* feat: implemented createStory

* feat: added support for createStory

* feat: improved Story deletion

- Deletes comments on the deleted Story
- Deletes actions of comments that were deleted via new
  `root_item_id` parameter for Comment Action's
- Added logging around critical components of the remove
  process

* feat: implemented mergeStory

- Added new merge function for root actions
- Added new merge function for story comments
- Added new merge function for comment status counts
- Added new remove stories function

* fix: fixed story creation method

* fix: added action count merging

* fix: removed outdated file

* fix: removed queue that got duplicated via rebase

* fix: prevent error when action counts are empty
This commit is contained in:
Wyatt Johnson
2018-11-02 23:18:12 +00:00
committed by GitHub
parent 7aa9a6b4f7
commit ca12b73b55
32 changed files with 1123 additions and 232 deletions
@@ -0,0 +1,64 @@
import { graphql } from "react-relay";
import { Environment } from "relay-runtime";
import {
commitMutationPromiseNormalized,
createMutationContainer,
} from "talk-framework/lib/relay";
import { RemoveCommentReactionMutation as MutationTypes } from "talk-stream/__generated__/RemoveCommentReactionMutation.graphql";
import { CreateCommentReactionInput } from "talk-stream/mutations/CreateCommentReactionMutation";
const mutation = graphql`
mutation RemoveCommentReactionMutation($input: CreateCommentReactionInput!) {
removeCommentReaction(input: $input) {
comment {
...ReactionButtonContainer_comment
}
clientMutationId
}
}
`;
const clientMutationId = 0;
function commit(environment: Environment, input: CreateCommentReactionInput) {
const source = environment.getStore().getSource();
const currentCount = source.get(
source.get(source.get(input.commentID)!.actionCounts.__ref)!.reaction.__ref
)!.total;
return commitMutationPromiseNormalized<MutationTypes>(environment, {
mutation,
variables: {
input: {
...input,
clientMutationId: clientMutationId.toString(),
},
},
optimisticResponse: {
removeCommentReaction: {
comment: {
id: input.commentID,
myActionPresence: {
reaction: false,
},
actionCounts: {
reaction: {
total: currentCount - 1,
},
},
},
clientMutationId: clientMutationId.toString(),
},
} as any, // TODO: (cvle) generated types should contain one for the optimistic response.
});
}
export const withRemoveCommentReactionMutation = createMutationContainer(
"removeCommentReaction",
commit
);
export type RemoveCommentReactionMutation = (
input: CreateCommentReactionInput
) => Promise<MutationTypes["response"]["removeCommentReaction"]>;