writeRoot writes the root function as well as any ordering and paging specified in q. Only uid(0x123, 0x124), type(...) and eq(Type.Predicate, ...) functions are supported at root. Multiple arguments for `eq` filter will be required in case of resolving `entities` query.
(b *strings.Builder, q *dql.GraphQuery)
| 151 | // Only uid(0x123, 0x124), type(...) and eq(Type.Predicate, ...) functions are supported at root. |
| 152 | // Multiple arguments for `eq` filter will be required in case of resolving `entities` query. |
| 153 | func writeRoot(b *strings.Builder, q *dql.GraphQuery) { |
| 154 | if q.Func == nil { |
| 155 | return |
| 156 | } |
| 157 | |
| 158 | switch { |
| 159 | // TODO: Instead of the hard-coded strings "uid", "type", etc., use the |
| 160 | // pre-defined constants in dql/parser.go such as dql.uidFunc, dql.typFunc, |
| 161 | // etc. This of course will require that we make these constants public. |
| 162 | case q.Func.Name == "uid": |
| 163 | x.Check2(b.WriteString("(func: ")) |
| 164 | writeUIDFunc(b, q.Func.UID, q.Func.Args) |
| 165 | case q.Func.Name == "type" && len(q.Func.Args) == 1: |
| 166 | x.Check2(b.WriteString(fmt.Sprintf("(func: type(%s)", q.Func.Args[0].Value))) |
| 167 | case q.Func.Name == "eq": |
| 168 | x.Check2(b.WriteString("(func: eq(")) |
| 169 | writeFilterArguments(b, q.Func.Args) |
| 170 | x.Check2(b.WriteRune(')')) |
| 171 | case q.Func.Name == "similar_to": |
| 172 | x.Check2(b.WriteString("(func: similar_to(")) |
| 173 | writeFilterArguments(b, q.Func.Args) |
| 174 | x.Check2(b.WriteRune(')')) |
| 175 | } |
| 176 | writeOrderAndPage(b, q, true) |
| 177 | x.Check2(b.WriteRune(')')) |
| 178 | } |
| 179 | |
| 180 | func writeFilterArguments(b *strings.Builder, args []dql.Arg) { |
| 181 | for i, arg := range args { |
no test coverage detected