diff --git a/client/coral-embed-stream/src/containers/Embed.js b/client/coral-embed-stream/src/containers/Embed.js index 72290fdea..fee127993 100644 --- a/client/coral-embed-stream/src/containers/Embed.js +++ b/client/coral-embed-stream/src/containers/Embed.js @@ -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} `; diff --git a/client/coral-embed-stream/src/containers/Stream.js b/client/coral-embed-stream/src/containers/Stream.js index 4f5018c2a..4df7fc960 100644 --- a/client/coral-embed-stream/src/containers/Stream.js +++ b/client/coral-embed-stream/src/containers/Stream.js @@ -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} diff --git a/client/coral-framework/helpers/plugins.js b/client/coral-framework/helpers/plugins.js index c284cae43..9961ea54e 100644 --- a/client/coral-framework/helpers/plugins.js +++ b/client/coral-framework/helpers/plugins.js @@ -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; diff --git a/client/coral-framework/utils/index.js b/client/coral-framework/utils/index.js index 4e9c29db7..64f543a49 100644 --- a/client/coral-framework/utils/index.js +++ b/client/coral-framework/utils/index.js @@ -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; +} +