From 512767e0232894aa04687a08e15238ce3cce1784 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 25 May 2017 17:49:30 +0700 Subject: [PATCH] Use default response fragments --- client/coral-admin/src/graphql/index.js | 32 --------------- .../coral-embed-stream/src/graphql/index.js | 39 ------------------- client/coral-framework/graphql/fragments.js | 23 ++++++++++- client/coral-framework/graphql/mutations.js | 39 +++++++++++++++++++ 4 files changed, 61 insertions(+), 72 deletions(-) diff --git a/client/coral-admin/src/graphql/index.js b/client/coral-admin/src/graphql/index.js index 8d369ebd7..f71e1b993 100644 --- a/client/coral-admin/src/graphql/index.js +++ b/client/coral-admin/src/graphql/index.js @@ -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'], diff --git a/client/coral-embed-stream/src/graphql/index.js b/client/coral-embed-stream/src/graphql/index.js index ccf6195f6..cee92d348 100644 --- a/client/coral-embed-stream/src/graphql/index.js +++ b/client/coral-embed-stream/src/graphql/index.js @@ -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 { diff --git a/client/coral-framework/graphql/fragments.js b/client/coral-framework/graphql/fragments.js index f4948ed05..9c396cbaa 100644 --- a/client/coral-framework/graphql/fragments.js +++ b/client/coral-framework/graphql/fragments.js @@ -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() +}; diff --git a/client/coral-framework/graphql/mutations.js b/client/coral-framework/graphql/mutations.js index d9c3cfe45..2af4c53ce 100644 --- a/client/coral-framework/graphql/mutations.js +++ b/client/coral-framework/graphql/mutations.js @@ -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 + } } } `, {