mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 15:36:46 +08:00
Introduce getDefinitionName
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user