Introduce getDefinitionName

This commit is contained in:
Chi Vinh Le
2017-04-26 01:07:07 +07:00
parent f79af56468
commit df2c33ac35
4 changed files with 22 additions and 11 deletions
@@ -6,6 +6,7 @@ import isEqual from 'lodash/isEqual';
import {Spinner} from 'coral-ui';
import {authActions, assetActions, pym} from 'coral-framework';
import {getDefinitionName} from 'coral-framework/utils';
import Embed from '../components/Embed';
import {setCommentCountCache, viewAllComments} from '../actions/stream';
import {setActiveTab} from '../actions/embed';
@@ -68,7 +69,7 @@ const EMBED_QUERY = gql`
me {
status
}
...Stream_root
...${getDefinitionName(Stream.fragments.root)}
}
${Stream.fragments.root}
`;
@@ -13,6 +13,7 @@ import {setCommentCountCache, setActiveReplyBox} from '../actions/stream';
import Stream from '../components/Stream';
import Comment from './Comment';
import withFragments from 'coral-framework/hocs/withFragments';
import {getDefinitionName} from 'coral-framework/utils';
const {showSignInDialog} = authActions;
const {addNotification} = notificationActions;
@@ -153,10 +154,10 @@ const LOAD_COMMENT_COUNTS_QUERY = gql`
const LOAD_MORE_QUERY = gql`
query LoadMoreComments($limit: Int = 5, $cursor: Date, $parent_id: ID, $asset_id: ID, $sort: SORT_ORDER, $excludeIgnored: Boolean) {
new_top_level_comments: comments(query: {limit: $limit, cursor: $cursor, parent_id: $parent_id, asset_id: $asset_id, sort: $sort, excludeIgnored: $excludeIgnored}) {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
replyCount(excludeIgnored: $excludeIgnored)
replies(limit: 3) {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
}
}
}
@@ -167,16 +168,16 @@ const fragments = {
root: gql`
fragment Stream_root on RootQuery {
comment(id: $commentId) @include(if: $hasComment) {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
replyCount(excludeIgnored: $excludeIgnored)
replies {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
}
parent {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
replyCount(excludeIgnored: $excludeIgnored)
replies {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
}
}
}
@@ -205,10 +206,10 @@ const fragments = {
commentCount(excludeIgnored: $excludeIgnored)
totalCommentCount(excludeIgnored: $excludeIgnored)
comments(limit: 10, excludeIgnored: $excludeIgnored) {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
replyCount(excludeIgnored: $excludeIgnored)
replies(limit: 3, excludeIgnored: $excludeIgnored) {
...Comment_comment
...${getDefinitionName(Comment.fragments.comment)}
}
}
}
@@ -219,7 +220,7 @@ const fragments = {
me {
status
}
...Comment_root
...${getDefinitionName(Comment.fragments.root)}
}
${Comment.fragments.root}
${Comment.fragments.comment}
+2 -1
View File
@@ -5,6 +5,7 @@ import flattenDeep from 'lodash/flattenDeep';
import uniq from 'lodash/uniq';
import plugins from 'pluginsConfig';
import {gql} from 'react-apollo';
import {getDefinitionName} from 'coral-framework/utils';
export const pluginReducers = merge(
...plugins
@@ -32,7 +33,7 @@ function getComponentFragments(components) {
if (!(key in res)) {
res[key] = {spreads: '', definitions: ''};
}
res[key].spreads += `...${fragments[key].definitions[0].name.value}\n`;
res[key].spreads += `...${getDefinitionName(fragments[key])}\n`;
res[key].definitions = gql`${res[key].definitions}${fragments[key]}`;
});
return res;
+8
View File
@@ -29,3 +29,11 @@ export const getMyActionSummary = (type, comment) => {
export const getActionSummary = (type, comment) => {
return comment.action_summaries.filter(a => a.__typename === type);
};
/**
* Get name of first (or $pos-th) definition
*/
export function getDefinitionName(doc, pos = 0) {
return doc.definitions[pos].name.value;
}