You just need a variable-length path and a WHERE all() predicate to restrict the labels of the middle nodes of the path:
... // assume 'path' variable used in the match
WHERE all(node in nodes(path)[1..-1] WHERE node:Beta)
...
Alternately, you can use APOC Procedures, as the options for the path expander should be able to deliver what you want:
MATCH (a:Alpha)
CALL apoc.path.expandConfig(a, {relationshipFilter: '>', labelFilter:'/Alpha|+Beta' filterStartNode:false}) YIELD path
RETURN path
The label filter is the key here. /Alpha
creates a termination node filter on :Alpha nodes, meaning that paths will be traversed only up to the first :Alpha node encountered and not beyond, and the paths returned will always end with an Alpha node. +Beta
creates a whitelist filter on :Beta nodes for nodes in the path (which doesn't apply to the end node when we use a termination filter), and the filterStartNode:false
means the start node isn't subject to the whitelist filter either.
This ensures that paths only go to the first :Alpha node, and all middle nodes in the path must be :Beta nodes.