Query with filter issue (both in and eq required, but then panics)

Note: the issue described below happens with dgraph/dgraph:a3d48429, but also with earlier versions.

I have following GraphQL query:

query QueryRestaurantOrders ($status:OrderStatus!) {
queryRestaurant_Order (order:{asc:restaurant_name},filter:{status:{eq:$status,in:$status}}){
created_at
status
}
}

where status field is an enum type.
Sometimes this query returns correct result, but sometimes it panics with:

E1109 12:00:07.742333 18 panics.go:33] panic: interface conversion: interface {} is string, not interface {}.
trace: goroutine 71017 [running]:
runtime/debug.Stack(0xc00128d5b8, 0x1b42100, 0xc003775950)
/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/dgraph-io/dgraph/graphql/api.PanicHandler(0xc00128df28)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/api/panics.go:33 +0x57
panic(0x1b42100, 0xc003775950)
/usr/local/go/src/runtime/panic.go:969 +0x166
github.com/dgraph-io/dgraph/graphql/resolve.buildFilter(0x1fa4c00, 0xc001ef1e40, 0xc003775800, 0x2)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query_rewriter.go:1268 +0x2218
github.com/dgraph-io/dgraph/graphql/resolve.addFilter(0xc00172a000, 0x1fa4c00, 0xc001ef1e40, 0xc003775800, 0xc003775800)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query_rewriter.go:1166 +0x1c5
github.com/dgraph-io/dgraph/graphql/resolve.addArgumentsToField(0xc00172a000, 0x7fa6fd5ad160, 0xc003775350)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query_rewriter.go:312 +0x98
github.com/dgraph-io/dgraph/graphql/resolve.rewriteAsQuery(0x7fa6fd5ad160, 0xc003775350, 0xc00128dbe0, 0x7fa6fd5ad160)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query_rewriter.go:471 +0xcc
github.com/dgraph-io/dgraph/graphql/resolve.(*queryRewriter).Rewrite(0x2fd91a0, 0x1f88b80, 0xc0037744b0, 0x1fac860, 0xc003775350, 0x203000, 0xc003775410, 0x8)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query_rewriter.go:132 +0x4cd
github.com/dgraph-io/dgraph/graphql/resolve.(*queryResolver).rewriteAndExecute(0xc0037753b0, 0x1f88b80, 0xc0037744b0, 0x1fac860, 0xc003775350, 0xc0037753b0)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query.go:137 +0x22c
github.com/dgraph-io/dgraph/graphql/resolve.(*queryResolver).Resolve(0xc0037753b0, 0x1f88b80, 0xc0037744b0, 0x1fac860, 0xc003775350, 0x0)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/query.go:86 +0x32d
github.com/dgraph-io/dgraph/graphql/resolve.(*RequestResolver).Resolve.func2.1(0xc00239bcc0, 0xc00024ccb8, 0x1, 0x1, 0xc0004d0ac0, 0x1f88b80, 0xc0037744b0, 0x1fac860, 0xc003775350, 0x0)
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/resolver.go:467 +0x165
created by github.com/dgraph-io/dgraph/graphql/resolve.(*RequestResolver).Resolve.func2
/ext-go/1/src/github.com/dgraph-io/dgraph/graphql/resolve/resolver.go:457 +0x1e0

I had to use both in and eq, because giving just one of them returns errors:

query QueryRestaurantOrders ($status:OrderStatus!) {
queryRestaurant_Order (order:{asc:restaurant_name},filter:{status:{eq:$status}){
created_at
status
}
}

“message”: “Field OrderStatus_hash.in of required type OrderStatus! was not provided.”

query QueryRestaurantOrders ($status:OrderStatus!) {
queryRestaurant_Order (order:{asc:restaurant_name},filter:{status:{in:$status}){
created_at
status
}
}
“message”: “Field OrderStatus_hash.eq of required type OrderStatus! was not provided.”

I have a type Restaurant_Order - originally wanted to have RestaurantOrder, but got error: “RestaurantOrder is a reserved word, so you can’t declare a OBJECT with this name. Pick a different name for the OBJECT.” (I have also Restaurant type defined).

I wasn’t able to create a test with simple example (it works OK for simple cases).

Thanks, @miko for reporting this. I have reproduced it and will pick this up soon. Till then you can try removing the condition of nonNull for the status field and it should work fine.

1 Like

Thanks for the workaround, works as expected for now.