Skip to content

Commit

Permalink
Breaking change: Remove expand(_forward_) and expand(_reverse_). (#4119)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr authored Oct 14, 2019
1 parent 3933ad1 commit bd05fa4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 67 deletions.
4 changes: 2 additions & 2 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
21 changes: 1 addition & 20 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
29 changes: 0 additions & 29 deletions query/query4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
21 changes: 7 additions & 14 deletions wiki/content/query-language/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit bd05fa4

Please sign in to comment.