Skip to content

Commit

Permalink
fix filter empty nodes (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildan2711 committed Jan 9, 2021
1 parent 388264a commit 69481ed
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ func (q *Query) node(jsonData []byte, dst interface{}) error {
// remove prefix and the ending array closer ']'
dataBytes := jsonData[dataPrefixLen : dataLen-2]

// if dgraph.type predicate not found, must be empty node
hasType := strings.Contains(string(dataBytes), predicateDgraphType)
if len(dataBytes) == 0 || !hasType {
if len(dataBytes) == 0 {
return ErrNodeNotFound
}

Expand Down Expand Up @@ -526,10 +524,18 @@ func (q *Query) generateQuery(queryBuf *strings.Builder) {
queryBuf.WriteString(") ")
// END ROOT FUNCTION

// make sure deleted nodes are not returned
typeIsNotNull := "has(dgraph.type)"
if q.filter != "" {
queryBuf.WriteString("@filter(")
queryBuf.WriteString(typeIsNotNull)
queryBuf.WriteString(" AND ")
queryBuf.WriteString(q.filter)
queryBuf.WriteString(") ")
} else {
queryBuf.WriteString("@filter(")
queryBuf.WriteString(typeIsNotNull)
queryBuf.WriteString(") ")
}

if q.groupBy != "" {
Expand Down

0 comments on commit 69481ed

Please sign in to comment.