Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change: Remove expand(_forward_) and expand(_reverse_). #4119

Merged
merged 4 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2802,10 +2802,6 @@ func godeep(it *lex.ItemIterator, gq *GraphQuery) error {
child.Expand = child.NeedsVar[len(child.NeedsVar)-1].Name
case "_all_":
child.Expand = "_all_"
case "_forward_":
child.Expand = "_forward_"
case "_reverse_":
child.Expand = "_reverse_"
martinmr marked this conversation as resolved.
Show resolved Hide resolved
default:
return item.Errorf("Invalid argument %v in expand()", item.Val)
}
Expand Down
28 changes: 0 additions & 28 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,6 @@ func TestParseQueryListPred1(t *testing.T) {
require.NoError(t, err)
}

func TestParseQueryExpandForward(t *testing.T) {
query := `
{
var(func: uid( 0x0a)) {
friends {
expand(_forward_)
}
}
}
`
_, err := Parse(Request{Str: query})
require.NoError(t, err)
}

func TestParseQueryExpandReverse(t *testing.T) {
query := `
{
var(func: uid( 0x0a)) {
friends {
expand(_reverse_)
}
}
}
`
_, err := Parse(Request{Str: query})
require.NoError(t, err)
}

func TestParseQueryAliasListPred(t *testing.T) {
query := `
{
Expand Down
21 changes: 1 addition & 20 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,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)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's val(x)? I have never any example like this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a variable that gets predicates values from the old _predicate_ func. To expand a query with those preds. It was like "expand only the preds found in the _predicate_ func".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pasted from my reply in Reviewable: "It takes a variable (a list of string values) and uses those values as the names of the predicates to expand. We should discuss whether to keep it but I left it untouched for now."

case "_all_":
span.Annotate(nil, "expand(_all_)")
if len(types) == 0 {
Expand All @@ -1837,25 +1837,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
7 changes: 1 addition & 6 deletions wiki/content/query-language/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1800,10 +1800,6 @@ There are four ways to use the `expand` function.
* If `_all_` is passed as an argument to `expand()`, all the predicates for each
martinmr marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down Expand Up @@ -2509,8 +2505,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