diff --git a/gql/parser.go b/gql/parser.go index f7d0d55ac59..9535f49f2b6 100644 --- a/gql/parser.go +++ b/gql/parser.go @@ -857,10 +857,6 @@ L: if err := parseRecurseArgs(it, gq); err != nil { return nil, err } - case "type": - if err := parseType(it, gq); err != nil { - return nil, err - } default: return nil, item.Errorf("Unknown directive [%s]", item.Val) } @@ -2022,40 +2018,6 @@ func parseGroupby(it *lex.ItemIterator, gq *GraphQuery) error { return nil } -func parseType(it *lex.ItemIterator, gq *GraphQuery) error { - it.Next() - if it.Item().Typ != itemLeftRound { - return it.Item().Errorf("Expected a left round after type") - } - - it.Next() - if it.Item().Typ != itemName { - return it.Item().Errorf("Expected a type name inside type directive") - } - typeName := it.Item().Val - - it.Next() - if it.Item().Typ != itemRightRound { - return it.Item().Errorf("Expected ) after the type name in type directive") - } - - // For now @type(TypeName) is equivalent of filtering using the type function. - // Later the type declarations will be used to ensure that the fields inside - // each block correspond to the specified type. - gq.Filter = &FilterTree{ - Func: &Function{ - Name: "type", - Args: []Arg{ - { - Value: typeName, - }, - }, - }, - } - - return nil -} - // parseFilter parses the filter directive to produce a QueryFilter / parse tree. func parseFilter(it *lex.ItemIterator) (*FilterTree, error) { it.Next() @@ -2288,11 +2250,6 @@ func parseDirective(it *lex.ItemIterator, curp *GraphQuery) error { if err := parseGroupby(it, curp); err != nil { return err } - case "type": - err := parseType(it, curp) - if err != nil { - return err - } default: return item.Errorf("Unknown directive [%s]", item.Val) } diff --git a/gql/parser_test.go b/gql/parser_test.go index 592bdeb8111..2161dcf007f 100644 --- a/gql/parser_test.go +++ b/gql/parser_test.go @@ -4780,76 +4780,3 @@ func TestTypeFilterInPredicate(t *testing.T) { require.Equal(t, 1, len(gq.Query[0].Children[0].Children)) require.Equal(t, "name", gq.Query[0].Children[0].Children[0].Attr) } - -func TestTypeInRoot(t *testing.T) { - q := ` - query { - me(func: uid(0x01)) @type(Person) { - name - } - }` - gq, err := Parse(Request{Str: q}) - require.NoError(t, err) - require.Equal(t, 1, len(gq.Query)) - require.Equal(t, "uid", gq.Query[0].Func.Name) - require.Equal(t, 1, len(gq.Query[0].Children)) - require.Equal(t, "name", gq.Query[0].Children[0].Attr) - - require.Equal(t, "type", gq.Query[0].Filter.Func.Name) - require.Equal(t, 1, len(gq.Query[0].Filter.Func.Args)) - require.Equal(t, "Person", gq.Query[0].Filter.Func.Args[0].Value) -} - -func TestTypeInPredicate(t *testing.T) { - q := ` - query { - me(func: uid(0x01)) { - friend @type(Person) { - name - } - } - }` - gq, err := Parse(Request{Str: q}) - require.NoError(t, err) - require.Equal(t, 1, len(gq.Query)) - require.Equal(t, "uid", gq.Query[0].Func.Name) - require.Equal(t, 1, len(gq.Query[0].Children)) - require.Equal(t, "friend", gq.Query[0].Children[0].Attr) - - require.Equal(t, "type", gq.Query[0].Children[0].Filter.Func.Name) - require.Equal(t, 1, len(gq.Query[0].Children[0].Filter.Func.Args)) - require.Equal(t, "Person", gq.Query[0].Children[0].Filter.Func.Args[0].Value) - - require.Equal(t, 1, len(gq.Query[0].Children[0].Children)) - require.Equal(t, "name", gq.Query[0].Children[0].Children[0].Attr) -} - -func TestMultipleTypeDirectives(t *testing.T) { - q := ` - query { - me(func: uid(0x01)) { - friend @type(Person) { - pet @type(Animal) { - name - } - } - } - }` - gq, err := Parse(Request{Str: q}) - require.NoError(t, err) - require.Equal(t, 1, len(gq.Query)) - require.Equal(t, "uid", gq.Query[0].Func.Name) - require.Equal(t, 1, len(gq.Query[0].Children)) - require.Equal(t, "friend", gq.Query[0].Children[0].Attr) - - require.Equal(t, "type", gq.Query[0].Children[0].Filter.Func.Name) - require.Equal(t, 1, len(gq.Query[0].Children[0].Filter.Func.Args)) - require.Equal(t, "Person", gq.Query[0].Children[0].Filter.Func.Args[0].Value) - - require.Equal(t, 1, len(gq.Query[0].Children[0].Children)) - require.Equal(t, "pet", gq.Query[0].Children[0].Children[0].Attr) - - require.Equal(t, "type", gq.Query[0].Children[0].Children[0].Filter.Func.Name) - require.Equal(t, 1, len(gq.Query[0].Children[0].Children[0].Filter.Func.Args)) - require.Equal(t, "Animal", gq.Query[0].Children[0].Children[0].Filter.Func.Args[0].Value) -} diff --git a/query/query3_test.go b/query/query3_test.go index 617e3b6df15..91219a776fa 100644 --- a/query/query3_test.go +++ b/query/query3_test.go @@ -2090,37 +2090,6 @@ func TestTypeFilterUnknownType(t *testing.T) { require.JSONEq(t, `{"data": {"me":[]}}`, js) } -func TestTypeDirectiveInPredicate(t *testing.T) { - query := ` - { - me(func: uid(0x2)) { - enemy @type(Person) { - name - } - } - } - ` - js := processQueryNoErr(t, query) - require.JSONEq(t, `{"data": {"me":[{"enemy":[{"name":"Margaret"}, {"name":"Leonard"}]}]}}`, js) -} - -func TestMultipleTypeDirectivesInPredicate(t *testing.T) { - query := ` - { - me(func: uid(0x2)) { - enemy @type(Person) { - name - pet @type(Animal) { - name - } - } - } - } - ` - js := processQueryNoErr(t, query) - require.JSONEq(t, `{"data": {"me":[{"enemy":[{"name":"Margaret", "pet":[{"name":"Bear"}]}, {"name":"Leonard"}]}]}}`, js) -} - func TestMaxPredicateSize(t *testing.T) { // Create a string that has more than than 2^16 chars. var b strings.Builder