kensho-technologies/graphql-compiler

Support `@optional` directive use on macro edges

obi1kenobi opened this issue · 1 comments

Currently, the @optional directive may not be applied on macro edges. This is because definitions of macro edges are allowed to rely on the composition of multiple edges, and there is no general way to know which of these multiple edges the @optional semantics should apply to.

For macro edges whose definitions only rely on a single edge, this is simple -- when the macro edge is marked @optional, the only edge becomes @optional.

When the definition contains multiple edges, we need a way to allow the creator of the definition to specify which edges become @optional and which remain required when the macro edge is marked @optional. This is perhaps best accomplished by adding another directive that can only be used at macro definition time, and relying on it to mark edges in the definition that should become optional.

Problem: The result of an optional traversal is the same as the union of the result with mandatory traversal, and the result with no traversal. If you mark some edges inside the macro as mandatory-under-optional, this property no longer holds.

Proposal: I think defining the semantics such that all edges in the macro are optional by default will buy us a couple of years until someone requests mandatory-under-optional edges. It's also easy to implement and avoids the problem above. The only downside I see is that nested optionals are bad practice in OrientDB. But I think it's time to move on from prioritizing OrientDB.