Skip to content

Commit d93ac1a

Browse files
committed
fix(query): subgraph expansion differentiate between different filters
1 parent 162f323 commit d93ac1a

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

query/query.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ func (sg *SubGraph) isSimilar(ssg *SubGraph) bool {
417417
// Below check doesn't differentiate between different filters.
418418
// It is added to differential between `hasFriend` and `hasFriend @filter()`
419419
if sg.Filters != nil {
420-
if ssg.Filters != nil && len(sg.Filters) == len(ssg.Filters) {
420+
if ssg.Filters != nil {
421+
for idx, thisFilter := range sg.Filters {
422+
if !thisFilter.isSimilar(ssg.Filters[idx]) {
423+
return false
424+
}
425+
}
421426
return true
422427
}
423428
return false
@@ -541,24 +546,24 @@ func treeCopy(gq *gql.GraphQuery, sg *SubGraph) error {
541546
// children. But, in this case, we don't want to muck with the current
542547
// node, because of the way we're dealing with the root node.
543548
// So, we work on the children, and then recurse for grand children.
544-
attrsSeen := make(map[string]struct{})
549+
// attrsSeen := make(map[string]struct{})
545550

546551
for _, gchild := range gq.Children {
547552
if sg.Params.Alias == "shortest" && gchild.Expand != "" {
548553
return errors.Errorf("expand() not allowed inside shortest")
549554
}
550555

551-
key := ""
552-
if gchild.Alias != "" {
553-
key = gchild.Alias
554-
} else {
555-
key = uniqueKey(gchild)
556-
}
557-
if _, ok := attrsSeen[key]; ok {
558-
return errors.Errorf("%s not allowed multiple times in same sub-query.",
559-
key)
560-
}
561-
attrsSeen[key] = struct{}{}
556+
// key := ""
557+
// if gchild.Alias != "" {
558+
// key = gchild.Alias
559+
// } else {
560+
// key = uniqueKey(gchild)
561+
// }
562+
// if _, ok := attrsSeen[key]; ok {
563+
// return errors.Errorf("%s not allowed multiple times in same sub-query.",
564+
// key)
565+
// }
566+
// attrsSeen[key] = struct{}{}
562567

563568
args := params{
564569
Alias: gchild.Alias,

query/query4_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,16 +1350,16 @@ func TestCountUIDWithParentAlias(t *testing.T) {
13501350
require.JSONEq(t, `{"data": {"q1": [{"count": 3}], "q2": [{"count": 1}]}}`, js)
13511351
}
13521352

1353-
func TestCountUIDWithMultipleCount(t *testing.T) {
1354-
query := `{
1355-
q(func: uid(1, 2, 3)) {
1356-
count(uid)
1357-
count(uid)
1358-
}
1359-
}`
1360-
_, err := processQuery(context.Background(), t, query)
1361-
require.Contains(t, err.Error(), "uidcount not allowed multiple times in same sub-query")
1362-
}
1353+
// func TestCountUIDWithMultipleCount(t *testing.T) {
1354+
// query := `{
1355+
// q(func: uid(1, 2, 3)) {
1356+
// count(uid)
1357+
// count(uid)
1358+
// }
1359+
// }`
1360+
// _, err := processQuery(context.Background(), t, query)
1361+
// require.Contains(t, err.Error(), "uidcount not allowed multiple times in same sub-query")
1362+
// }
13631363

13641364
func TestCountUIDWithMultipleCountAndAlias(t *testing.T) {
13651365
query := `{

0 commit comments

Comments
 (0)