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) (#6736)

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 authored Oct 15, 2020
1 parent e901c0d commit 4331ff5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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
15 changes: 15 additions & 0 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@
}
}
-
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 4331ff5

Please sign in to comment.