Skip to content

Commit d1bb2c2

Browse files
JatinDev543aman-bansal
authored andcommitted
fix(GRAPHQL): fixed output coercing for admin fields. (#7617)
Fixes GRAPHQL-1100 We were getting output coercing error for fields like maxNodes in admin/state because internally that return value of type UInt64 but we were parsing it to Int. So we added UInt64 in GraphQL output types , Int64 in admin schema and changed the fields types accordingly in admin types.
1 parent 3f84915 commit d1bb2c2

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

graphql/admin/admin.go

+33-17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ const (
4646

4747
// GraphQL schema for /admin endpoint.
4848
graphqlAdminSchema = `
49+
"""
50+
The Int64 scalar type represents a signed 64‐bit numeric non‐fractional value.
51+
Int64 can represent values in range [-(2^63),(2^63 - 1)].
52+
"""
53+
scalar Int64
54+
55+
"""
56+
The UInt64 scalar type represents a unsigned 64‐bit numeric non‐fractional value.
57+
UInt64 can represent values in range [0,(2^64 - 1)].
58+
"""
59+
scalar UInt64
60+
61+
"""
62+
The DateTime scalar type represents date and time as a string in RFC3339 format.
63+
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.
64+
"""
4965
scalar DateTime
5066
5167
"""
@@ -100,12 +116,12 @@ const (
100116
"""
101117
Time in nanoseconds since the node started.
102118
"""
103-
uptime: Int
119+
uptime: Int64
104120
105121
"""
106122
Time in Unix epoch time that the node was last contacted by another Zero or Alpha node.
107123
"""
108-
lastEcho: Int
124+
lastEcho: Int64
109125
110126
"""
111127
List of ongoing operations in the background.
@@ -124,51 +140,51 @@ const (
124140
}
125141
126142
type MembershipState {
127-
counter: Int
143+
counter: UInt64
128144
groups: [ClusterGroup]
129145
zeros: [Member]
130-
maxUID: Int
131-
maxNsID: Int
132-
maxTxnTs: Int
133-
maxRaftId: Int
146+
maxUID: UInt64
147+
maxNsID: UInt64
148+
maxTxnTs: UInt64
149+
maxRaftId: UInt64
134150
removed: [Member]
135151
cid: String
136152
license: License
137153
}
138154
139155
type ClusterGroup {
140-
id: Int
156+
id: UInt64
141157
members: [Member]
142158
tablets: [Tablet]
143-
snapshotTs: Int
144-
checksum: Int
159+
snapshotTs: UInt64
160+
checksum: UInt64
145161
}
146162
147163
type Member {
148-
id: Int
149-
groupId: Int
164+
id: UInt64
165+
groupId: UInt64
150166
addr: String
151167
leader: Boolean
152168
amDead: Boolean
153-
lastUpdate: Int
169+
lastUpdate: UInt64
154170
clusterInfoOnly: Boolean
155171
forceGroupId: Boolean
156172
}
157173
158174
type Tablet {
159-
groupId: Int
175+
groupId: UInt64
160176
predicate: String
161177
force: Boolean
162178
space: Int
163179
remove: Boolean
164180
readOnly: Boolean
165-
moveTs: Int
181+
moveTs: UInt64
166182
}
167183
168184
type License {
169185
user: String
170-
maxNodes: Int
171-
expiryTs: Int
186+
maxNodes: UInt64
187+
expiryTs: Int64
172188
enabled: Boolean
173189
}
174190

graphql/admin/endpoints_ee.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const adminTypes = `
172172
"""
173173
The ID of the cluster group.
174174
"""
175-
groupId: Int
175+
groupId: UInt64
176176
177177
"""
178178
List of predicates assigned to the group.
@@ -189,7 +189,7 @@ const adminTypes = `
189189
"""
190190
Number of this backup within the backup series. The full backup always has a value of one.
191191
"""
192-
backupNum: Int
192+
backupNum: UInt64
193193
194194
"""
195195
Whether this backup was encrypted.
@@ -210,7 +210,7 @@ const adminTypes = `
210210
The timestamp at which this backup was taken. The next incremental backup will
211211
start from this timestamp.
212212
"""
213-
since: Int
213+
since: UInt64
214214
215215
"""
216216
The type of backup, either full or incremental.
@@ -417,7 +417,7 @@ const adminTypes = `
417417
}
418418
419419
type NamespacePayload {
420-
namespaceId: Int
420+
namespaceId: UInt64
421421
message: String
422422
}
423423
@@ -430,7 +430,7 @@ const adminTypes = `
430430
type ResetPasswordPayload {
431431
userId: String
432432
message: String
433-
namespace: Int
433+
namespace: UInt64
434434
}
435435
`
436436

graphql/e2e/common/admin.go

+3
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func adminState(t *testing.T) {
434434
user
435435
expiryTs
436436
enabled
437+
maxNodes
437438
}
438439
}
439440
}`,
@@ -460,6 +461,7 @@ func adminState(t *testing.T) {
460461
User string
461462
ExpiryTs int64
462463
Enabled bool
464+
MaxNodes uint64
463465
}
464466
}
465467
}
@@ -512,5 +514,6 @@ func adminState(t *testing.T) {
512514
require.Equal(t, state.Cid, result.State.Cid)
513515
require.Equal(t, state.License.User, result.State.License.User)
514516
require.Equal(t, state.License.ExpiryTs, result.State.License.ExpiryTs)
517+
require.Equal(t, state.License.MaxNodes, result.State.License.MaxNodes)
515518
require.Equal(t, state.License.Enabled, result.State.License.Enabled)
516519
}

graphql/schema/completion.go

+11
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,17 @@ func coerceScalar(val interface{}, field Field, path []interface{}) (interface{}
429429
default:
430430
return nil, valueCoercionError(v)
431431
}
432+
// UInt64 is present only in admin schema.
433+
case "UInt64":
434+
switch v := val.(type) {
435+
case json.Number:
436+
if _, err := strconv.ParseUint(v.String(), 10, 64); err != nil {
437+
return nil, valueCoercionError(v)
438+
}
439+
// do nothing, as val is already a valid number in UInt64 range
440+
default:
441+
return nil, valueCoercionError(v)
442+
}
432443
case "Float":
433444
switch v := val.(type) {
434445
case bool:

0 commit comments

Comments
 (0)