Help with the post filtering after the apoc.path.subgraphAll

Hello,
I'm trying to get all the related nodes starting from the specific one. I want to filter by properties stored in the nodes and relationships.
I started with the cypher syntax, but has been blocked by the performance and finally switched to the apoc.

My initial apoc query was like that:

MATCH (p: MyFirstLabel {id: 'some-id'})
CALL apoc.path.subgraphAll(p, {minLevel: 0}) yield nodes, relationships

Then, I wanted to add the logic to get only nodes that has relationships created in the certain time period. I was able to write something like this one:

MATCH (p: MyFirstLabel {id: 'some-id'})
CALL apoc.path.subgraphAll(p, {minLevel: 0}) yield nodes, relationships
MATCH (start_node) - [relation] - (end_node)
WHERE
    id(relation) IN [r IN relationships | id(r)]
    AND relation.created >= datetime('2022-10-01')
    AND relation.created < datetime('2023-01-01')
RETURN start_node, relation, end_node

This query work pretty well, but still there is a problem that it can return multiple subgraphs that are not connected anymore (because of the filtering I'm applying on the previous step).

Can you advise me a better / right way to filter the subgraph from the subgraphAll output?

Thanks!

MATCH (p: MyFirstLabel {id: 'some-id'})
CALL apoc.path.subgraphAll(p, {minLevel: 0}) yield relationships
UNWIND [r IN relationships where r.created >= datetime('2022-10-01')
    AND r.created < datetime('2023-01-01') |
{start_node: startNode(r), end_node: endNode(r), relationship_properties: properties(r)}] as result

You can chose alternate forms of the output if desired, but this will give a list of the relationship data as maps.

Thank you @glilienfield for a quick response! ,
Your solution looks pretty good however I see exactly the same problem that I have in my solution.

I'll give more examples to make it clearer.
Let's imagine I have this dataset:

MERGE (f1: MyNode {id: 1})
MERGE (f2: MyNode {id: 2})
MERGE (f3: MyNode {id: 3})
MERGE (f4: MyNode {id: 4})
MERGE (f5: MyNode {id: 5})
MERGE (f6: MyNode {id: 6})
MERGE (f7: MyNode {id: 7})
MERGE (f8: MyNode {id: 8})
MERGE (f9: MyNode {id: 9})
MERGE (f10: MyNode {id: 10})

MERGE (f1)-[:MyEdge {some_index: 1}]->(f1)
MERGE (f2)-[:MyEdge {some_index: 1}]->(f3)
MERGE (f3)-[:MyEdge {some_index: 1}]->(f4)
MERGE (f4)-[:MyEdge {some_index: 2}]->(f5)
MERGE (f5)-[:MyEdge {some_index: 2}]->(f6)
MERGE (f6)-[:MyEdge {some_index: 2}]->(f7)
MERGE (f7)-[:MyEdge {some_index: 3}]->(f8)
MERGE (f8)-[:MyEdge {some_index: 3}]->(f9)
MERGE (f9)-[:MyEdge {some_index: 1}]->(f10)

Which gives a graph like this one:
image

Now, if I'm running your query (or mine from the initial post) I have next result :

MATCH (n: MyNode {id: 1}) CALL apoc.path.subgraphAll(n, {minLevel:1}) yield relationships
UNWIND [r IN relationships where r.some_index <> 2 |
{start_node: startNode(r), end_node: endNode(r), relationship_properties: properties(r)}] as result
RETURN result

image

As you can see it returns nodes 2, 3, and 4 what is expected as they are still connected to the node 1. However, it also returns the nodes 7, 8, 9 and 10 as they were connected to the node 1 before the filtering.
What I really want to return in this case is the 1, 2, 3, and 4 but ignore the nodes that are not connected to the initial node anymore (7, 8, 9, 10).

So actually I'm looking for something like this pure cypher query:

MATCH (n:MyNode {id: 1}) - [r* {some_index: 1}] -> (m) return r, m, n

But, as I've mentioned before I can't use it because of performance reasons.

I hope it's clearer now.

So, are you looking to get the longest path starting from the anchor node where all relationships along the path match your constraint. Thus, you want to ignore all nodes along the path after the first relationships that does not match your constraint. Is this accurate?

That's pretty close. I'm interesting to get all nodes where all relationships along the paths match my constraint.
In the example I've attached earlier there is only one type of node, to make it clearer (I hoped to give an easily reproductible example). But in reality there a lof of connected nodes with different types, so from my understanding there are more than one paths to get all the nodes without duplications.

Something like on this image (copied from here)

P.S. I'm really sorry if I'm not clear enough. I'm just starting an exploration of the subject.