Skip to content

Commit

Permalink
fix(GraphQL): This PR fix panic error when we give null value in filt…
Browse files Browse the repository at this point in the history
…er connectives. (#6707)

Fixes GRAPHQL-744

This PR fix panic error when we give null value in filter connectives. Null values corresponding to connective are skipped now.
For example in the below filter, not connective gets skipped.

```

 filter:{
      id:{eq:"123"},
      not:null
    },

```

(cherry picked from commit 345b6d1)
  • Loading branch information
JatinDev543 committed Oct 14, 2020
1 parent c2d5e66 commit 3e9ce8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions graphql/resolve/query_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,9 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree
// Each key in filter is either "and", "or", "not" or the field name it
// applies to such as "title" in: `title: { anyofterms: "GraphQL" }``
for _, field := range keys {
if filter[field] == nil {
continue
}
switch field {

// In 'and', 'or' and 'not' cases, filter[field] must be a map[string]interface{}
Expand Down
16 changes: 15 additions & 1 deletion graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,21 @@
dgraph.uid : uid
}
}
-
name: "Filter connectives with null values gets skipped "
gqlquery: |
query {
queryAuthor(filter: { name: { eq: "A. N. Author" },not:null }) {
name
}
}
dgquery: |-
query {
queryAuthor(func: type(Author)) @filter(eq(Author.name, "A. N. Author")) {
name : Author.name
dgraph.uid : uid
}
}
-
name: "Filters in same input object implies AND"
gqlquery: |
Expand Down

0 comments on commit 3e9ce8b

Please sign in to comment.