Ensure that emitted relations are deduplicated
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Ensure that emitted relations are deduplicated
|
||||
@@ -57,6 +57,7 @@ deadnaming
|
||||
debounce
|
||||
Debounce
|
||||
declaratively
|
||||
deduplicated
|
||||
deps
|
||||
destructured
|
||||
dev
|
||||
|
||||
@@ -74,6 +74,13 @@ describe('Stitcher', () => {
|
||||
type: 'looksAt',
|
||||
target_entity_ref: 'k:ns/other',
|
||||
},
|
||||
// handles and ignores duplicates
|
||||
{
|
||||
originating_entity_id: 'my-id',
|
||||
source_entity_ref: 'k:ns/n',
|
||||
type: 'looksAt',
|
||||
target_entity_ref: 'k:ns/other',
|
||||
},
|
||||
]);
|
||||
|
||||
await stitcher.stitch(new Set(['k:ns/n']));
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from '@backstage/catalog-model';
|
||||
import { SerializedError } from '@backstage/errors';
|
||||
import { Knex } from 'knex';
|
||||
import { uniqBy } from 'lodash';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
@@ -168,7 +169,11 @@ export class Stitcher {
|
||||
|
||||
// TODO: entityRef is lower case and should be uppercase in the final
|
||||
// result
|
||||
entity.relations = result
|
||||
const uniqueRelationRows = uniqBy(
|
||||
result,
|
||||
r => `${r.relationType}:${r.relationTarget}`,
|
||||
);
|
||||
entity.relations = uniqueRelationRows
|
||||
.filter(row => row.relationType /* exclude null row, if relevant */)
|
||||
.map(row => ({
|
||||
type: row.relationType!,
|
||||
|
||||
Reference in New Issue
Block a user