Skip to content

Commit

Permalink
Fix response for partial admin queries. (#5317)
Browse files Browse the repository at this point in the history
Handle `[]map[string]interface{}` separately from `[]interface{}` in `completObject` function. This fixes the bug where admin queries returned full info even when asked for partial information.
  • Loading branch information
pawanrawal authored Apr 28, 2020
1 parent e98240d commit aa4ece9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions graphql/e2e/common/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/dgraph-io/dgo/v200"
"github.com/dgraph-io/dgo/v200/protos/api"
"github.com/dgraph-io/dgraph/protos/pb"
"github.com/dgraph-io/dgraph/testutil"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -429,6 +430,34 @@ func health(t *testing.T) {
}
}

func partialHealth(t *testing.T) {
queryParams := &GraphQLParams{
Query: `query {
health {
instance
status
group
}
}`,
}
gqlResponse := queryParams.ExecuteAsPost(t, graphqlAdminTestAdminURL)
RequireNoGQLErrors(t, gqlResponse)
testutil.CompareJSON(t, `{
"health": [
{
"instance": "zero",
"status": "healthy",
"group": "0"
},
{
"instance": "alpha",
"status": "healthy",
"group": "1"
}
]
}`, string(gqlResponse.Data))
}

// The GraphQL /admin state result should be the same as /state
func adminState(t *testing.T) {
queryParams := &GraphQLParams{
Expand Down
1 change: 1 addition & 0 deletions graphql/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func RunAll(t *testing.T) {
// admin tests
t.Run("admin", admin)
t.Run("health", health)
t.Run("partial health", partialHealth)
t.Run("state", adminState)
t.Run("propagate client remote ip", clientInfoLogin)

Expand Down
8 changes: 8 additions & 0 deletions graphql/resolve/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,14 @@ func completeValue(
return completeObject(path, field.SelectionSet(), val)
case []interface{}:
return completeList(path, field, val)
case []map[string]interface{}:
// This case is different from the []interface{} case above and is true for admin queries
// where we built the val ourselves.
listVal := make([]interface{}, 0, len(val))
for _, v := range val {
listVal = append(listVal, v)
}
return completeList(path, field, listVal)
default:
if val == nil {
if field.Type().ListType() != nil {
Expand Down

0 comments on commit aa4ece9

Please sign in to comment.