I managed to get it working. I realised that the Set couldn't work out that the objects in it were not unique, so I had to stringify them first.
I don't think this is the best implementation (I'm looping through the array several times) but it does work.
Here is my solution to get this to work:
const collections = allCollectionsByType.map(({ node }) => {
const collection = node.collections.edges?.[0]?.node;
return JSON.stringify(collection);
});
const unique = Array.from(new Set(collections))
.filter((node) => typeof node === 'string')
.map((node: string) => JSON.parse(node));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…