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 15, 2020
1 parent 1ec276c commit 8794514
Show file tree
Hide file tree
Showing 2 changed files with 34 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
31 changes: 31 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 Expand Up @@ -199,6 +214,22 @@
}
}
-
name: "has Filter with nested 'and'"
gqlquery: |
query {
queryAuthor(filter: { name: { eq: "A. N. Author" }, and: { dob: { le: "2001-01-01" }, and: { has: country } } } ) {
name
}
}
dgquery: |-
query {
queryAuthor(func: type(Author)) @filter(((has(Author.country) AND le(Author.dob, "2001-01-01")) AND eq(Author.name, "A. N. Author"))) {
name : Author.name
dgraph.uid : uid
}
}
-
name: "Filter with 'or'"
gqlquery: |
Expand Down

0 comments on commit 8794514

Please sign in to comment.