Skip to content

Commit

Permalink
fix(plugin-workflow): merge queries through the queries envelope not …
Browse files Browse the repository at this point in the history
…the unit field
  • Loading branch information
critocrito committed Nov 15, 2019
1 parent 72426cc commit ca386d9
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions packages/plugin-workflow/lib/plugins/merge-query.js
Expand Up @@ -17,37 +17,44 @@ const plugin = (envelope, {cfg, log}) => {
)}`,
);

return env.fmapData(
unit =>
unit._sc_queries.reduce((memo, query) => {
const toMerge = fields.reduce((acc, field) => {
const oldValue = get(field, unit);
const newValue = get(field, query);
return env.fmapData(unit => {
const queries = envelope.queries.filter(
({type, term}) =>
unit._sc_queries.find(
query => query.type === type && query.term === term,
) != null,
);

if (!overwrite && oldValue != null) {
log.info(
`Not overwriting ${oldValue} with ${newValue} for field ${field} in ${query.type}/${unit._sc_id_hash}`,
);
return acc;
}
return queries.reduce((memo, query) => {
const toMerge = fields.reduce((acc, field) => {
const oldValue = get(field, unit);
const newValue = get(field, query);

if (overwrite && oldValue != null) {
log.info(
`Overwriting ${oldValue} with ${newValue} for field ${field} in ${query.type}/${unit._sc_id_hash}`,
);
} else {
log.info(
`Merging ${newValue} for field ${field} in ${query.type}/${unit._sc_id_hash}`,
);
}
if (!overwrite && oldValue != null) {
log.info(
`Not overwriting ${oldValue} with ${newValue} for field ${field} in ${query.type}/${unit._sc_id_hash}`,
);
return acc;
}

return deepmerge(acc, set(field, newValue, {}));
}, {});
if (overwrite && oldValue != null) {
log.info(
`Overwriting ${oldValue} with ${newValue} for field ${field} in ${query.type}/${unit._sc_id_hash}`,
);
} else {
log.info(
`Merging ${newValue} for field ${field} in ${query.type}/${unit._sc_id_hash}`,
);
}

return deepmerge(memo, toMerge);
}, unit),
envelope,
);
if (newValue == null) return acc;

return deepmerge(acc, set(field, newValue, {}));
}, {});

return deepmerge(memo, toMerge);
}, unit);
}, envelope);
};

plugin.argv = {
Expand Down

0 comments on commit ca386d9

Please sign in to comment.