diff --git a/graphql/resolve/query_rewriter.go b/graphql/resolve/query_rewriter.go index 05facaa2eb5..eacbff4de76 100644 --- a/graphql/resolve/query_rewriter.go +++ b/graphql/resolve/query_rewriter.go @@ -1020,6 +1020,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{} @@ -1076,7 +1079,6 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree for _, v := range vals { args = append(args, gql.Arg{Value: maybeQuoteArg(fn, v)}) } - case "near": // For Geo type we have `near` filter which is written as follows: // { near: { distance: 33.33, coordinate: { latitude: 11.11, longitude: 22.22 } } } @@ -1086,11 +1088,10 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree coordinate, _ := geoParams["coordinate"].(map[string]interface{}) lat := coordinate["latitude"] long := coordinate["longitude"] + args = append(args, gql.Arg{Value: fmt.Sprintf("[%v,%v]", long, lat)}, + gql.Arg{Value: fmt.Sprintf("%v", distance)}) - args = append(args, gql.Arg{Value: fmt.Sprintf("[%v,%v]", long, lat)}) - args = append(args, gql.Arg{Value: fmt.Sprintf("%v", distance)}) - - default: + default: args = append(args, gql.Arg{Value: maybeQuoteArg(fn, val)}) } ands = append(ands, &gql.FilterTree{ @@ -1098,7 +1099,7 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree Name: fn, Args: args, }, - }) + }) case []interface{}: // ids: [ 0x123, 0x124 ] -> uid(0x123, 0x124) ids := convertIDs(dgFunc) diff --git a/graphql/resolve/query_test.yaml b/graphql/resolve/query_test.yaml index 1ef5bf57ee4..a3efd655ba7 100644 --- a/graphql/resolve/query_test.yaml +++ b/graphql/resolve/query_test.yaml @@ -15,7 +15,7 @@ dgraph.uid : uid } } - + - name: "Geo query" gqlquery: | @@ -206,6 +206,22 @@ } } +- + 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: "Query with has Filter" gqlquery: |