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

fix(GRAPHQL): fixed output coercing for admin fields. #7617

Merged
merged 2 commits into from
Mar 19, 2021
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
50 changes: 33 additions & 17 deletions graphql/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ const (

// GraphQL schema for /admin endpoint.
graphqlAdminSchema = `
"""
The Int64 scalar type represents a signed 64‐bit numeric non‐fractional value.
Int64 can represent values in range [-(2^63),(2^63 - 1)].
"""
scalar Int64

"""
The UInt64 scalar type represents a unsigned 64‐bit numeric non‐fractional value.
UInt64 can represent values in range [0,(2^64 - 1)].
"""
scalar UInt64

"""
The DateTime scalar type represents date and time as a string in RFC3339 format.
For example: "1985-04-12T23:20:50.52Z" represents 20 minutes and 50.52 seconds after the 23rd hour of April 12th, 1985 in UTC.
"""
scalar DateTime

"""
Expand Down Expand Up @@ -100,12 +116,12 @@ const (
"""
Time in nanoseconds since the node started.
"""
uptime: Int
uptime: Int64

"""
Time in Unix epoch time that the node was last contacted by another Zero or Alpha node.
"""
lastEcho: Int
lastEcho: Int64

"""
List of ongoing operations in the background.
Expand All @@ -124,51 +140,51 @@ const (
}

type MembershipState {
counter: Int
counter: UInt64
groups: [ClusterGroup]
zeros: [Member]
maxUID: Int
maxNsID: Int
maxTxnTs: Int
maxRaftId: Int
maxUID: UInt64
maxNsID: UInt64
maxTxnTs: UInt64
maxRaftId: UInt64
removed: [Member]
cid: String
license: License
}

type ClusterGroup {
id: Int
id: UInt64
members: [Member]
tablets: [Tablet]
snapshotTs: Int
checksum: Int
snapshotTs: UInt64
checksum: UInt64
}

type Member {
id: Int
groupId: Int
id: UInt64
groupId: UInt64
addr: String
leader: Boolean
amDead: Boolean
lastUpdate: Int
lastUpdate: UInt64
clusterInfoOnly: Boolean
forceGroupId: Boolean
}

type Tablet {
groupId: Int
groupId: UInt64
predicate: String
force: Boolean
space: Int
remove: Boolean
readOnly: Boolean
moveTs: Int
moveTs: UInt64
}

type License {
user: String
maxNodes: Int
expiryTs: Int
maxNodes: UInt64
expiryTs: Int64
enabled: Boolean
}

Expand Down
10 changes: 5 additions & 5 deletions graphql/admin/endpoints_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const adminTypes = `
"""
The ID of the cluster group.
"""
groupId: Int
groupId: UInt64

"""
List of predicates assigned to the group.
Expand All @@ -189,7 +189,7 @@ const adminTypes = `
"""
Number of this backup within the backup series. The full backup always has a value of one.
"""
backupNum: Int
backupNum: UInt64

"""
Whether this backup was encrypted.
Expand All @@ -210,7 +210,7 @@ const adminTypes = `
The timestamp at which this backup was taken. The next incremental backup will
start from this timestamp.
"""
since: Int
since: UInt64

"""
The type of backup, either full or incremental.
Expand Down Expand Up @@ -417,7 +417,7 @@ const adminTypes = `
}

type NamespacePayload {
namespaceId: Int
namespaceId: UInt64
message: String
}

Expand All @@ -430,7 +430,7 @@ const adminTypes = `
type ResetPasswordPayload {
userId: String
message: String
namespace: Int
namespace: UInt64
}
`

Expand Down
3 changes: 3 additions & 0 deletions graphql/e2e/common/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func adminState(t *testing.T) {
user
expiryTs
enabled
maxNodes
}
}
}`,
Expand All @@ -460,6 +461,7 @@ func adminState(t *testing.T) {
User string
ExpiryTs int64
Enabled bool
MaxNodes uint64
}
}
}
Expand Down Expand Up @@ -512,5 +514,6 @@ func adminState(t *testing.T) {
require.Equal(t, state.Cid, result.State.Cid)
require.Equal(t, state.License.User, result.State.License.User)
require.Equal(t, state.License.ExpiryTs, result.State.License.ExpiryTs)
require.Equal(t, state.License.MaxNodes, result.State.License.MaxNodes)
require.Equal(t, state.License.Enabled, result.State.License.Enabled)
}
11 changes: 11 additions & 0 deletions graphql/schema/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@ func coerceScalar(val interface{}, field Field, path []interface{}) (interface{}
default:
return nil, valueCoercionError(v)
}
// UInt64 is present only in admin schema.
case "UInt64":
switch v := val.(type) {
case json.Number:
if _, err := strconv.ParseUint(v.String(), 10, 64); err != nil {
return nil, valueCoercionError(v)
}
// do nothing, as val is already a valid number in UInt64 range
default:
return nil, valueCoercionError(v)
}
case "Float":
switch v := val.(type) {
case bool:
Expand Down