diff --git a/gql/parser.go b/gql/parser.go index 8b9c89cb41d..2dbf9dcf347 100644 --- a/gql/parser.go +++ b/gql/parser.go @@ -2804,9 +2804,9 @@ func godeep(it *lex.ItemIterator, gq *GraphQuery) error { case "_all_": child.Expand = "_all_" case "_forward_": - child.Expand = "_forward_" + return item.Errorf("Argument _forward_ has been deprecated") case "_reverse_": - child.Expand = "_reverse_" + return item.Errorf("Argument _reverse_ has been deprecated") default: return item.Errorf("Invalid argument %v in expand()", item.Val) } diff --git a/gql/parser_test.go b/gql/parser_test.go index f79ef2773f5..03766178d0b 100644 --- a/gql/parser_test.go +++ b/gql/parser_test.go @@ -171,7 +171,8 @@ func TestParseQueryExpandForward(t *testing.T) { } ` _, err := Parse(Request{Str: query}) - require.NoError(t, err) + require.Error(t, err) + require.Contains(t, err.Error(), "Argument _forward_ has been deprecated") } func TestParseQueryExpandReverse(t *testing.T) { @@ -185,7 +186,8 @@ func TestParseQueryExpandReverse(t *testing.T) { } ` _, err := Parse(Request{Str: query}) - require.NoError(t, err) + require.Error(t, err) + require.Contains(t, err.Error(), "Argument _reverse_ has been deprecated") } func TestParseQueryAliasListPred(t *testing.T) { diff --git a/query/query.go b/query/query.go index e7d0f168ab5..2de0b7daab2 100644 --- a/query/query.go +++ b/query/query.go @@ -1820,7 +1820,7 @@ func expandSubgraph(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) { } switch child.Params.Expand { - // It could be expand(_all_), expand(_forward_), expand(_reverse_) or expand(val(x)). + // It could be expand(_all_) or expand(val(x)). case "_all_": span.Annotate(nil, "expand(_all_)") if len(types) == 0 { @@ -1833,25 +1833,6 @@ func expandSubgraph(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) { return out, err } preds = append(preds, rpreds...) - case "_forward_": - span.Annotate(nil, "expand(_forward_)") - if len(types) == 0 { - break - } - - preds = getPredicatesFromTypes(types) - case "_reverse_": - span.Annotate(nil, "expand(_reverse_)") - if len(types) == 0 { - break - } - - typePreds := getPredicatesFromTypes(types) - rpreds, err := getReversePredicates(ctx, typePreds) - if err != nil { - return out, err - } - preds = append(preds, rpreds...) default: span.Annotate(nil, "expand default") // We already have the predicates populated from the var. diff --git a/query/query4_test.go b/query/query4_test.go index 72696019850..1f53ef370e2 100644 --- a/query/query4_test.go +++ b/query/query4_test.go @@ -296,35 +296,6 @@ func TestTypeExpandAll(t *testing.T) { ]}}`, js) } -func TestTypeExpandForward(t *testing.T) { - query := `{ - q(func: eq(make, "Ford")) { - expand(_forward_) { - uid - } - } - }` - js := processQueryNoErr(t, query) - require.JSONEq(t, `{"data": {"q":[ - {"make":"Ford","model":"Focus","year":2008}, - {"make":"Ford","model":"Focus","year":2009, "previous_model": {"uid":"0xc8"}} - ]}}`, js) -} - -func TestTypeExpandReverse(t *testing.T) { - query := `{ - q(func: eq(make, "Ford")) { - expand(_reverse_) { - uid - } - } - }` - js := processQueryNoErr(t, query) - require.JSONEq(t, `{"data": {"q":[ - {"~previous_model": [{"uid":"0xc9"}]} - ]}}`, js) -} - func TestTypeExpandLang(t *testing.T) { query := `{ q(func: eq(make, "Toyota")) { diff --git a/wiki/content/query-language/index.md b/wiki/content/query-language/index.md index 68642594034..51b441d37ad 100644 --- a/wiki/content/query-language/index.md +++ b/wiki/content/query-language/index.md @@ -1797,18 +1797,12 @@ There are four ways to use the `expand` function. * Predicates can be stored in a variable and passed to `expand()` to expand all the predicates in the variable. -* If `_all_` is passed as an argument to `expand()`, all the predicates for each - node at that level are retrieved. More levels can be specified in a nested - fashion under `expand()`. -* If `_forward_` is passed as an argument to `expand()`, all predicates for each - node at that level (minus any reverse predicates) are retrieved. -* If `_reverse_` is passed as an argument to `expand()`, only the reverse - predicates at each node in that level are retrieved. - -The last three keywords require that the nodes have types. Dgraph will look -for all the types that have been assigned to a node, -query the types to check which attributes they have, and use those to compute -the list of predicates to expand. +* If `_all_` is passed as an argument to `expand()`, the predicates to be +expanded will be the union of fields in the types assigned to a given node. + +The `_all_` keyword requires that the nodes have types. Dgraph will look for all +the types that have been assigned to a node, query the types to check which +attributes they have, and use those to compute the list of predicates to expand. For example, consider a node that has types `Animal` and `Pet`, which have the following definitions: @@ -2533,8 +2527,7 @@ err := c.Alter(context.Background(), &api.Operation{ ### Expand queries and types Queries using [expand]({{< relref "#expand-predicates" >}}) (i.e.: -`expand(_all_)`, `expand(_reverse_)`, or `expand(_forward_)`) require that the -nodes to expand have types. +`expand(_all_)`) require that the nodes to be expanded have types. ## Facets : Edge attributes