Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql: Fix response for partial admin queries. #5317

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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