diff --git a/client/coral-embed-stream/src/containers/Comment.js b/client/coral-embed-stream/src/containers/Comment.js index 4bad8aaab..524f7ec62 100644 --- a/client/coral-embed-stream/src/containers/Comment.js +++ b/client/coral-embed-stream/src/containers/Comment.js @@ -9,9 +9,9 @@ export default withFragments({ root: gql` fragment Comment_root on RootQuery { __typename - ${pluginFragments.root && pluginFragments.root.names} + ${pluginFragments.spreads('root')} } - ${pluginFragments.root && pluginFragments.root.definitions} + ${pluginFragments.definitions('root')} `, comment: gql` fragment Comment_comment on Comment { @@ -33,8 +33,8 @@ export default withFragments({ id } } - ${pluginFragments.comment && pluginFragments.comment.names} + ${pluginFragments.spreads('comment')} } - ${pluginFragments.comment && pluginFragments.comment.definitions} + ${pluginFragments.definitions('comment')} `, })(Comment); diff --git a/client/coral-framework/helpers/plugins.js b/client/coral-framework/helpers/plugins.js index 02f97b101..c284cae43 100644 --- a/client/coral-framework/helpers/plugins.js +++ b/client/coral-framework/helpers/plugins.js @@ -30,15 +30,18 @@ function getComponentFragments(components) { .reduce((res, fragments) => { Object.keys(fragments).forEach(key => { if (!(key in res)) { - res[key] = {names: '', definitions: ''}; + res[key] = {spreads: '', definitions: ''}; } - res[key].names += `...${fragments[key].definitions[0].name.value}\n`; + res[key].spreads += `...${fragments[key].definitions[0].name.value}\n`; res[key].definitions = gql`${res[key].definitions}${fragments[key]}`; }); return res; }, {}); } +/** + * @returns {[key]: {spreads: string, definitions: AST}} + */ export function getSlotsFragments(slots) { if (!Array.isArray(slots)) { slots = [slots]; @@ -49,6 +52,14 @@ export function getSlotsFragments(slots) { .map(o => o.module.slots[slot]); }))); - return getComponentFragments(components); + const fragments = getComponentFragments(components); + return { + spreads(key) { + return fragments[key] && fragments[key].spreads; + }, + definitions(key) { + return fragments[key] && fragments[key].definitions; + }, + }; }