From 028e13761f616cfe455a83c9710ed71e5b4fdee0 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 9 May 2017 03:05:19 +0700 Subject: [PATCH] Complete graphql code refactor in framework --- .../{fragments/index.js => fragments.js} | 0 .../fragments/actionSummaryView.graphql | 8 ---- .../graphql/fragments/commentView.graphql | 18 --------- .../{mutations/index.js => mutations.js} | 2 +- .../coral-framework/graphql/queries/index.js | 13 ------- .../graphql/queries/myCommentHistory.graphql | 14 ------- .../graphql/queries/myIgnoredUsers.graphql | 6 --- .../containers/ProfileContainer.js | 39 +++++++++++++++++-- 8 files changed, 36 insertions(+), 64 deletions(-) rename client/coral-framework/graphql/{fragments/index.js => fragments.js} (100%) delete mode 100644 client/coral-framework/graphql/fragments/actionSummaryView.graphql delete mode 100644 client/coral-framework/graphql/fragments/commentView.graphql rename client/coral-framework/graphql/{mutations/index.js => mutations.js} (98%) delete mode 100644 client/coral-framework/graphql/queries/index.js delete mode 100644 client/coral-framework/graphql/queries/myCommentHistory.graphql delete mode 100644 client/coral-framework/graphql/queries/myIgnoredUsers.graphql diff --git a/client/coral-framework/graphql/fragments/index.js b/client/coral-framework/graphql/fragments.js similarity index 100% rename from client/coral-framework/graphql/fragments/index.js rename to client/coral-framework/graphql/fragments.js diff --git a/client/coral-framework/graphql/fragments/actionSummaryView.graphql b/client/coral-framework/graphql/fragments/actionSummaryView.graphql deleted file mode 100644 index 4ac232bf6..000000000 --- a/client/coral-framework/graphql/fragments/actionSummaryView.graphql +++ /dev/null @@ -1,8 +0,0 @@ -fragment actionSummaryView on ActionSummary { - __typename - count - current_user { - id - created_at - } -} diff --git a/client/coral-framework/graphql/fragments/commentView.graphql b/client/coral-framework/graphql/fragments/commentView.graphql deleted file mode 100644 index 0ed5e00b8..000000000 --- a/client/coral-framework/graphql/fragments/commentView.graphql +++ /dev/null @@ -1,18 +0,0 @@ -#import "../fragments/actionSummaryView.graphql" - -fragment commentView on Comment { - id - body - created_at - status - tags { - name - } - user { - id - name: username - } - action_summaries { - ...actionSummaryView - } -} diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations.js similarity index 98% rename from client/coral-framework/graphql/mutations/index.js rename to client/coral-framework/graphql/mutations.js index f43c68dc0..1f1179b58 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations.js @@ -1,5 +1,5 @@ import {gql} from 'react-apollo'; -import withMutation from '../../hocs/withMutation'; +import withMutation from '../hocs/withMutation'; export const withPostComment = withMutation( gql` diff --git a/client/coral-framework/graphql/queries/index.js b/client/coral-framework/graphql/queries/index.js deleted file mode 100644 index d76614a68..000000000 --- a/client/coral-framework/graphql/queries/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import {graphql} from 'react-apollo'; -import MY_COMMENT_HISTORY from './myCommentHistory.graphql'; -import MY_IGNORED_USERS from './myIgnoredUsers.graphql'; - -export const myCommentHistory = graphql(MY_COMMENT_HISTORY, {}); - -export const myIgnoredUsers = graphql(MY_IGNORED_USERS, { - props: ({data}) => { - return ({ - myIgnoredUsersData: data - }); - } -}); diff --git a/client/coral-framework/graphql/queries/myCommentHistory.graphql b/client/coral-framework/graphql/queries/myCommentHistory.graphql deleted file mode 100644 index 0b37b192a..000000000 --- a/client/coral-framework/graphql/queries/myCommentHistory.graphql +++ /dev/null @@ -1,14 +0,0 @@ -query myCommentHistory { - me { - comments { - id - body - asset { - id - title - url - } - created_at - } - } -} diff --git a/client/coral-framework/graphql/queries/myIgnoredUsers.graphql b/client/coral-framework/graphql/queries/myIgnoredUsers.graphql deleted file mode 100644 index d81531e37..000000000 --- a/client/coral-framework/graphql/queries/myIgnoredUsers.graphql +++ /dev/null @@ -1,6 +0,0 @@ -query myIgnoredUsers { - myIgnoredUsers { - id, - username, - } -} diff --git a/client/coral-settings/containers/ProfileContainer.js b/client/coral-settings/containers/ProfileContainer.js index e289ff485..f9c8d892f 100644 --- a/client/coral-settings/containers/ProfileContainer.js +++ b/client/coral-settings/containers/ProfileContainer.js @@ -1,10 +1,9 @@ import {connect} from 'react-redux'; -import {compose} from 'react-apollo'; +import {compose, graphql, gql} from 'react-apollo'; import React, {Component} from 'react'; import I18n from 'coral-framework/modules/i18n/i18n'; import {bindActionCreators} from 'redux'; -import {myCommentHistory, myIgnoredUsers} from 'coral-framework/graphql/queries'; import {withStopIgnoringUser} from 'coral-framework/graphql/mutations'; import {link} from 'coral-framework/services/PymConnection'; @@ -88,6 +87,38 @@ class ProfileContainer extends Component { } } +// TODO: These currently relies on refetching (see ignoreUser and stopIgnoringUser mutations). +// +const withMyIgnoredUsersQuery = graphql(gql` + query myIgnoredUsers { + myIgnoredUsers { + id, + username, + } + }`, { + props: ({data}) => { + return ({ + myIgnoredUsersData: data + }); + } + }); + +const withMyCommentHistoryQuery = graphql(gql` + query myCommentHistory { + me { + comments { + id + body + asset { + id + title + url + } + created_at + } + } + }`); + const mapStateToProps = state => ({ user: state.user.toJS(), asset: state.asset.toJS(), @@ -99,7 +130,7 @@ const mapDispatchToProps = dispatch => export default compose( connect(mapStateToProps, mapDispatchToProps), - myCommentHistory, - myIgnoredUsers, + withMyCommentHistoryQuery, + withMyIgnoredUsersQuery, withStopIgnoringUser, )(ProfileContainer);