Skip to content

Commit

Permalink
Do not retrieve facets when max recurse depth has been reached. (#3190)
Browse files Browse the repository at this point in the history
Currently, recurse will retrive the facets at max depth, which results
in the facets being present in the results while the node on the other
side of the edge is absent from the result. This change modifies the
logic so that facets are only included if the node to which the edge
connects is included in the results as well.
  • Loading branch information
martinmr authored Mar 22, 2019
1 parent 04db751 commit e3edcce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions query/query_facets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,13 @@ func TestRecurseFacetOrder(t *testing.T) {
}
`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data":{"me":[{"friend":[{"uid":"0x19","name":"Daryl Dixon","friend|since":"2007-05-02T15:04:05Z"},{"friend":[{"friend|since":"2006-01-02T15:04:05Z"}],"uid":"0x17","name":"Rick Grimes","friend|since":"2006-01-02T15:04:05Z"},{"uid":"0x1f","name":"Andrea","friend|since":"2006-01-02T15:04:05Z"},{"uid":"0x65","friend|since":"2005-05-02T15:04:05Z"},{"uid":"0x18","name":"Glenn Rhee","friend|since":"2004-05-02T15:04:05Z"}],"uid":"0x1","name":"Michonne"}]}}`, js)
require.JSONEq(t, `{"data":{"me":[{"friend":[
{"uid":"0x19","name":"Daryl Dixon","friend|since":"2007-05-02T15:04:05Z"},
{"uid":"0x17","name":"Rick Grimes","friend|since":"2006-01-02T15:04:05Z"},
{"uid":"0x1f","name":"Andrea","friend|since":"2006-01-02T15:04:05Z"},
{"uid":"0x65","friend|since":"2005-05-02T15:04:05Z"},
{"uid":"0x18","name":"Glenn Rhee","friend|since":"2004-05-02T15:04:05Z"}],
"uid":"0x1","name":"Michonne"}]}}`, js)

query = `
{
Expand All @@ -852,7 +858,13 @@ func TestRecurseFacetOrder(t *testing.T) {
}
`
js = processQueryNoErr(t, query)
require.JSONEq(t, `{"data":{"me":[{"friend":[{"uid":"0x18","name":"Glenn Rhee","friend|since":"2004-05-02T15:04:05Z"},{"uid":"0x65","friend|since":"2005-05-02T15:04:05Z"},{"friend":[{"friend|since":"2006-01-02T15:04:05Z"}],"uid":"0x17","name":"Rick Grimes","friend|since":"2006-01-02T15:04:05Z"},{"uid":"0x1f","name":"Andrea","friend|since":"2006-01-02T15:04:05Z"},{"uid":"0x19","name":"Daryl Dixon","friend|since":"2007-05-02T15:04:05Z"}],"uid":"0x1","name":"Michonne"}]}}`, js)
require.JSONEq(t, `{"data":{"me":[{"friend":[
{"uid":"0x18","name":"Glenn Rhee","friend|since":"2004-05-02T15:04:05Z"},
{"uid":"0x65","friend|since":"2005-05-02T15:04:05Z"},
{"uid":"0x17","name":"Rick Grimes","friend|since":"2006-01-02T15:04:05Z"},
{"uid":"0x1f","name":"Andrea","friend|since":"2006-01-02T15:04:05Z"},
{"uid":"0x19","name":"Daryl Dixon","friend|since":"2007-05-02T15:04:05Z"}],
"uid":"0x1","name":"Michonne"}]}}`, js)
}

func TestFacetsAlias(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions query/recurse.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func (start *SubGraph) expandRecurse(ctx context.Context, maxDepth uint64) error
}
depth++

// When the maximum depth has been reached, avoid retrieving any facets as
// the nodes at the other end of the edge will not be a part of this query.
// Otherwise, the facets will be included in the query without any other
// information about the node, which is quite counter-intuitive.
if depth == maxDepth {
for _, sg := range exec {
sg.Params.Facet = nil
}
}

rrch := make(chan error, len(exec))
for _, sg := range exec {
go ProcessGraph(ctx, sg, dummy, rrch)
Expand Down

0 comments on commit e3edcce

Please sign in to comment.