Find matching sub-objects when filtering

Hi!

I have a content structure with three levels; A has a many-to-many relationship with B, which has a many-to-many relationship with C.

I have a function where I filter A on a field X of C, that is; “find all As which have a B which has a C which matches field X”. I’ve gotten this request to work, but as a response I only get the matching A:s.

While this response format is completely reasonable, I am interested in getting the matching A:s, but also the relational path to the matching C:s of each A. Is there any way to achieve this through the API, or have anyone else on the forum written some similar algorithm?
It gets pretty time complex, since my field on C also is an array of relations, and I want to enable filtering on multiple filter strings…

To be clear, what I want to be able to do is to display something like this “Found matching X in A > B > C”, not only “Found matching X in A”.