Skip to content

Commit 4331ff5

Browse files
authored
fix(GraphQL): This PR fix panic error when we give null value in filter 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)
1 parent e901c0d commit 4331ff5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

graphql/resolve/query_rewriter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,9 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree
10141014
// Each key in filter is either "and", "or", "not" or the field name it
10151015
// applies to such as "title" in: `title: { anyofterms: "GraphQL" }``
10161016
for _, field := range keys {
1017+
if filter[field] == nil {
1018+
continue
1019+
}
10171020
switch field {
10181021

10191022
// In 'and', 'or' and 'not' cases, filter[field] must be a map[string]interface{}

graphql/resolve/query_test.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@
167167
}
168168
}
169169
170+
-
171+
name: "Filter connectives with null values gets skipped "
172+
gqlquery: |
173+
query {
174+
queryAuthor(filter: { name: { eq: "A. N. Author" },not:null }) {
175+
name
176+
}
177+
}
178+
dgquery: |-
179+
query {
180+
queryAuthor(func: type(Author)) @filter(eq(Author.name, "A. N. Author")) {
181+
name : Author.name
182+
dgraph.uid : uid
183+
}
184+
}
170185
-
171186
name: "Filters in same input object implies AND"
172187
gqlquery: |

0 commit comments

Comments
 (0)