File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1150,6 +1150,10 @@ func (s *builder) hasActions() bool {
11501150 return len (s .projections ) > 0 || len (s .setItems ) > 0 || len (s .removeItems ) > 0 || len (s .creates ) > 0 || len (s .deleteItems ) > 0
11511151}
11521152
1153+ func (s * builder ) wantsShortestPathPattern () bool {
1154+ return s .shortestPathQuery || s .allShorestPathsQuery
1155+ }
1156+
11531157func (s * builder ) Build () (* PreparedQuery , error ) {
11541158 if len (s .errors ) > 0 {
11551159 return nil , errors .Join (s .errors ... )
@@ -1232,6 +1236,10 @@ func (s *builder) Build() (*PreparedQuery, error) {
12321236 matchIdentifiers := readIdentifiers .Clone ()
12331237 matchIdentifiers .Or (actionIdentifiers )
12341238
1239+ if s .wantsShortestPathPattern () && ! isRelationshipPattern (matchIdentifiers , s .identifiers ) {
1240+ return nil , fmt .Errorf ("shortest path query requires relationship query identifiers" )
1241+ }
1242+
12351243 if len (s .constraints ) > 0 || matchIdentifiers .Len () > 0 {
12361244 if isNodePattern (matchIdentifiers , s .identifiers ) {
12371245 if err := prepareNodePattern (match , matchIdentifiers , s .identifiers ); err != nil {
Original file line number Diff line number Diff line change @@ -238,6 +238,12 @@ func TestShortestPathControls(t *testing.T) {
238238 v2 .Path (),
239239 ).Build ()
240240 require .ErrorContains (t , err , "query is requesting both all shortest paths and shortest paths" )
241+
242+ _ , err = v2 .New ().WithShortestPaths ().Return (v2 .Node ()).Build ()
243+ require .ErrorContains (t , err , "shortest path query requires relationship query identifiers" )
244+
245+ _ , err = v2 .New ().WithAllShortestPaths ().Return (v2 .As (v2 .Literal (1 ), "one" )).Build ()
246+ require .ErrorContains (t , err , "shortest path query requires relationship query identifiers" )
241247}
242248
243249func TestMixedNodeAndRelationshipIdentifiersReturnError (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments