Skip to content

Commit 480486d

Browse files
committed
fix(query/v2): require relationship shortest paths
1 parent 7b11102 commit 480486d

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

query/v2/query.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
11531157
func (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 {

query/v2/query_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

243249
func TestMixedNodeAndRelationshipIdentifiersReturnError(t *testing.T) {

0 commit comments

Comments
 (0)