Use default response fragments

This commit is contained in:
Chi Vinh Le
2017-05-25 17:49:30 +07:00
parent 48a8e394ef
commit 512767e023
4 changed files with 61 additions and 72 deletions
-32
View File
@@ -1,39 +1,7 @@
import {add} from 'coral-framework/services/graphqlRegistry';
import {gql} from 'react-apollo';
const queues = ['all', 'premod', 'flagged', 'accepted', 'rejected'];
const extension = {
fragments: {
SetUserStatusResponse: gql`
fragment Admin_SetUserStatusResponse on SetUserStatusResponse {
errors {
translation_key
}
}
`,
SuspendUserResponse: gql`
fragment Admin_SuspendUserResponse on SuspendUserResponse {
errors {
translation_key
}
}
`,
RejectUsernameResponse: gql`
fragment Admin_RejectUsernameResponse on RejectUsernameResponse {
errors {
translation_key
}
}
`,
SetCommentStatusResponse: gql`
fragment Admin_SetCommentStatusResponse on SetCommentStatusResponse {
errors {
translation_key
}
}
`,
},
mutations: {
SetUserStatus: () => ({
refetchQueries: ['Admin_Community'],
@@ -9,23 +9,6 @@ const extension = {
comment {
status
}
errors {
translation_key
}
}
`,
StopIgnoringUserResponse: gql`
fragment CoralEmbedStream_StopIgnoringUserResponse on StopIgnoringUserResponse {
errors {
translation_key
}
}
`,
IgnoreUserResponse: gql`
fragment CoralEmbedStream_IgnoreUserResponse on IgnoreUserResponse {
errors {
translation_key
}
}
`,
RemoveCommentTagResponse: gql`
@@ -36,9 +19,6 @@ const extension = {
name
}
}
errors {
translation_key
}
}
`,
AddCommentTagResponse: gql`
@@ -49,16 +29,6 @@ const extension = {
name
}
}
errors {
translation_key
}
}
`,
DeleteActionResponse: gql`
fragment CoralEmbedStream_DeleteActionResponse on DeleteActionResponse {
errors {
translation_key
}
}
`,
CreateFlagResponse: gql`
@@ -66,9 +36,6 @@ const extension = {
flag {
id
}
errors {
translation_key
}
}
`,
CreateDontAgreeResponse : gql`
@@ -76,9 +43,6 @@ const extension = {
dontagree {
id
}
errors {
translation_key
}
}
`,
CreateCommentResponse: gql`
@@ -89,9 +53,6 @@ const extension = {
...CoralEmbedStream_CreateCommentResponse_Comment
}
}
errors {
translation_key
}
}
fragment CoralEmbedStream_CreateCommentResponse_Comment on Comment {
+22 -1
View File
@@ -1,2 +1,23 @@
import {gql} from 'react-apollo';
import * as mutations from './mutations';
function createDefaultResponseFragments() {
const names = Object.keys(mutations).map((key) => key.replace('with', ''));
const result = {};
names.forEach((name) => {
const response = `${name}Response`;
result[response] = gql`
fragment Coral_${response} on ${response} {
errors {
translation_key
}
}
`;
});
return result;
}
// fragments defined here are automatically registered.
export default {};
export default {
...createDefaultResponseFragments()
};
@@ -6,6 +6,9 @@ export const withSetCommentStatus = withMutation(
mutation SetCommentStatus($commentId: ID!, $status: COMMENT_STATUS!){
setCommentStatus(id: $commentId, status: $status) {
...SetCommentStatusResponse
errors {
translation_key
}
}
}
`, {
@@ -26,6 +29,9 @@ export const withSuspendUser = withMutation(
mutation SuspendUser($input: SuspendUserInput!) {
suspendUser(input: $input) {
...SuspendUserResponse
errors {
translation_key
}
}
}
`, {
@@ -45,6 +51,9 @@ export const withRejectUsername = withMutation(
mutation RejectUsername($input: RejectUsernameInput!) {
rejectUsername(input: $input) {
...RejectUsernameResponse
errors {
translation_key
}
}
}
`, {
@@ -64,6 +73,9 @@ export const withSetUserStatus = withMutation(
mutation SetUserStatus($userId: ID!, $status: USER_STATUS!) {
setUserStatus(id: $userId, status: $status) {
...SetUserStatusResponse
errors {
translation_key
}
}
}
`, {
@@ -84,6 +96,9 @@ export const withPostComment = withMutation(
mutation PostComment($comment: CreateCommentInput!) {
createComment(comment: $comment) {
...CreateCommentResponse
errors {
translation_key
}
}
}
`, {
@@ -103,6 +118,9 @@ export const withEditComment = withMutation(
mutation EditComment($id: ID!, $asset_id: ID!, $edit: EditCommentInput) {
editComment(id:$id, asset_id:$asset_id, edit:$edit) {
...EditCommentResponse
errors {
translation_key
}
}
}
`, {
@@ -124,6 +142,9 @@ export const withPostFlag = withMutation(
mutation PostFlag($flag: CreateFlagInput!) {
createFlag(flag: $flag) {
...CreateFlagResponse
errors {
translation_key
}
}
}
`, {
@@ -142,6 +163,9 @@ export const withPostDontAgree = withMutation(
mutation CreateDontAgree($dontagree: CreateDontAgreeInput!) {
createDontAgree(dontagree: $dontagree) {
...CreateDontAgreeResponse
errors {
translation_key
}
}
}
`, {
@@ -160,6 +184,9 @@ export const withDeleteAction = withMutation(
mutation DeleteAction($id: ID!) {
deleteAction(id:$id) {
...DeleteActionResponse
errors {
translation_key
}
}
}
`, {
@@ -178,6 +205,9 @@ export const withAddCommentTag = withMutation(
mutation AddCommentTag($id: ID!, $tag: String!) {
addCommentTag(id:$id, tag:$tag) {
...AddCommentTagResponse
errors {
translation_key
}
}
}
`, {
@@ -197,6 +227,9 @@ export const withRemoveCommentTag = withMutation(
mutation RemoveCommentTag($id: ID!, $tag: String!) {
removeCommentTag(id:$id, tag:$tag) {
...RemoveCommentTagResponse
errors {
translation_key
}
}
}
`, {
@@ -216,6 +249,9 @@ export const withIgnoreUser = withMutation(
mutation IgnoreUser($id: ID!) {
ignoreUser(id:$id) {
...IgnoreUserResponse
errors {
translation_key
}
}
}
`, {
@@ -234,6 +270,9 @@ export const withStopIgnoringUser = withMutation(
mutation StopIgnoringUser($id: ID!) {
stopIgnoringUser(id:$id) {
...StopIgnoringUserResponse
errors {
translation_key
}
}
}
`, {