Query to detect a missing edge

Hello, I’m trying to write a specific query, and just cannot work out how to achieve this one. Any help appreciated!

For every Edge1 in my database, this exact pattern should exist. However in some cases Edge3 can be missing, so I’m trying to find all Node3-Node4 pairs where Edge3 is missing (or even better, add the link in directly).

Ideally I need to iterate through all Edge1’s in a single query, as there are many millions of them and I do not want to issue a query for each edge.

This is the best query I managed to come up with:

upsert {
  query {
    A as var(func:has(Node1.Edge1)) {~Node4.Edge4 {B as uid}}
	
	var(func:uid(A)) {
	  Node1.Edge1 {
		~Node3.Edge2 {
          C as uid
          ~Node4.Edge3 @filter(uid(B))
           {D as uid}
		}
	  }
    }
  }

  mutation @if(not eq(len(D), 1)) {
    set {
      uid(B) <Node4.Edge3> uid(C) .
    }
  }
}

However this has the issue that is will cartesian all B’s and C’s together from all results, it is not limited to just this one loop/pattern.

I also tried standard queries to just return the B/C pairs with missing Edge3’s, but all had this cartesian problem whatever I tried.