Skip to content

Commit ff6d819

Browse files
fix: change uint64 type INT to NUMERIC
1 parent 6a0819f commit ff6d819

File tree

3 files changed

+207
-71
lines changed

3 files changed

+207
-71
lines changed

public/graphql/schema.graphql

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,13 +3427,13 @@ type ClaimCollection implements Node {
34273427
protocol: String!
34283428
startDate: Datetime
34293429
endDate: Datetime
3430-
quota: Int!
3431-
count: Int!
3432-
evaluated: Int!
3433-
approved: Int!
3434-
rejected: Int!
3435-
disputed: Int!
3436-
invalidated: Int!
3430+
quota: BigFloat!
3431+
count: BigFloat!
3432+
evaluated: BigFloat!
3433+
approved: BigFloat!
3434+
rejected: BigFloat!
3435+
disputed: BigFloat!
3436+
invalidated: BigFloat!
34373437
state: Int!
34383438
payments: JSON!
34393439

@@ -3475,6 +3475,11 @@ type ClaimCollection implements Node {
34753475
claimSchemaTypesLoaded: Boolean!
34763476
}
34773477

3478+
"""
3479+
A floating point number that requires more precision than IEEE 754 binary 64
3480+
"""
3481+
scalar BigFloat
3482+
34783483
"""Methods to use when ordering `Claim`."""
34793484
enum ClaimsOrderBy {
34803485
NATURAL
@@ -3586,7 +3591,7 @@ input EvaluationFilter {
35863591
status: IntFilter
35873592

35883593
"""Filter by the object’s `reason` field."""
3589-
reason: IntFilter
3594+
reason: BigFloatFilter
35903595

35913596
"""Filter by the object’s `verificationProof` field."""
35923597
verificationProof: StringFilter
@@ -3613,6 +3618,48 @@ input EvaluationFilter {
36133618
not: EvaluationFilter
36143619
}
36153620

3621+
"""
3622+
A filter to be used against BigFloat fields. All fields are combined with a logical ‘and.’
3623+
"""
3624+
input BigFloatFilter {
3625+
"""
3626+
Is null (if `true` is specified) or is not null (if `false` is specified).
3627+
"""
3628+
isNull: Boolean
3629+
3630+
"""Equal to the specified value."""
3631+
equalTo: BigFloat
3632+
3633+
"""Not equal to the specified value."""
3634+
notEqualTo: BigFloat
3635+
3636+
"""
3637+
Not equal to the specified value, treating null like an ordinary value.
3638+
"""
3639+
distinctFrom: BigFloat
3640+
3641+
"""Equal to the specified value, treating null like an ordinary value."""
3642+
notDistinctFrom: BigFloat
3643+
3644+
"""Included in the specified list."""
3645+
in: [BigFloat!]
3646+
3647+
"""Not included in the specified list."""
3648+
notIn: [BigFloat!]
3649+
3650+
"""Less than the specified value."""
3651+
lessThan: BigFloat
3652+
3653+
"""Less than or equal to the specified value."""
3654+
lessThanOrEqualTo: BigFloat
3655+
3656+
"""Greater than the specified value."""
3657+
greaterThan: BigFloat
3658+
3659+
"""Greater than or equal to the specified value."""
3660+
greaterThanOrEqualTo: BigFloat
3661+
}
3662+
36163663
"""
36173664
A filter to be used against `ClaimCollection` object types. All fields are combined with a logical ‘and.’
36183665
"""
@@ -3636,25 +3683,25 @@ input ClaimCollectionFilter {
36363683
endDate: DatetimeFilter
36373684

36383685
"""Filter by the object’s `quota` field."""
3639-
quota: IntFilter
3686+
quota: BigFloatFilter
36403687

36413688
"""Filter by the object’s `count` field."""
3642-
count: IntFilter
3689+
count: BigFloatFilter
36433690

36443691
"""Filter by the object’s `evaluated` field."""
3645-
evaluated: IntFilter
3692+
evaluated: BigFloatFilter
36463693

36473694
"""Filter by the object’s `approved` field."""
3648-
approved: IntFilter
3695+
approved: BigFloatFilter
36493696

36503697
"""Filter by the object’s `rejected` field."""
3651-
rejected: IntFilter
3698+
rejected: BigFloatFilter
36523699

36533700
"""Filter by the object’s `disputed` field."""
3654-
disputed: IntFilter
3701+
disputed: BigFloatFilter
36553702

36563703
"""Filter by the object’s `invalidated` field."""
3657-
invalidated: IntFilter
3704+
invalidated: BigFloatFilter
36583705

36593706
"""Filter by the object’s `state` field."""
36603707
state: IntFilter
@@ -3708,7 +3755,7 @@ type Evaluation implements Node {
37083755
agentDid: String!
37093756
agentAddress: String!
37103757
status: Int!
3711-
reason: Int!
3758+
reason: BigFloat!
37123759
verificationProof: String
37133760
amount: JSON!
37143761
evaluationDate: Datetime!
@@ -3816,25 +3863,25 @@ input ClaimCollectionCondition {
38163863
endDate: Datetime
38173864

38183865
"""Checks for equality with the object’s `quota` field."""
3819-
quota: Int
3866+
quota: BigFloat
38203867

38213868
"""Checks for equality with the object’s `count` field."""
3822-
count: Int
3869+
count: BigFloat
38233870

38243871
"""Checks for equality with the object’s `evaluated` field."""
3825-
evaluated: Int
3872+
evaluated: BigFloat
38263873

38273874
"""Checks for equality with the object’s `approved` field."""
3828-
approved: Int
3875+
approved: BigFloat
38293876

38303877
"""Checks for equality with the object’s `rejected` field."""
3831-
rejected: Int
3878+
rejected: BigFloat
38323879

38333880
"""Checks for equality with the object’s `disputed` field."""
3834-
disputed: Int
3881+
disputed: BigFloat
38353882

38363883
"""Checks for equality with the object’s `invalidated` field."""
3837-
invalidated: Int
3884+
invalidated: BigFloat
38383885

38393886
"""Checks for equality with the object’s `state` field."""
38403887
state: Int
@@ -4829,53 +4876,6 @@ input TokenRetiredSumAggregateFilter {
48294876
amount: BigFloatFilter
48304877
}
48314878

4832-
"""
4833-
A filter to be used against BigFloat fields. All fields are combined with a logical ‘and.’
4834-
"""
4835-
input BigFloatFilter {
4836-
"""
4837-
Is null (if `true` is specified) or is not null (if `false` is specified).
4838-
"""
4839-
isNull: Boolean
4840-
4841-
"""Equal to the specified value."""
4842-
equalTo: BigFloat
4843-
4844-
"""Not equal to the specified value."""
4845-
notEqualTo: BigFloat
4846-
4847-
"""
4848-
Not equal to the specified value, treating null like an ordinary value.
4849-
"""
4850-
distinctFrom: BigFloat
4851-
4852-
"""Equal to the specified value, treating null like an ordinary value."""
4853-
notDistinctFrom: BigFloat
4854-
4855-
"""Included in the specified list."""
4856-
in: [BigFloat!]
4857-
4858-
"""Not included in the specified list."""
4859-
notIn: [BigFloat!]
4860-
4861-
"""Less than the specified value."""
4862-
lessThan: BigFloat
4863-
4864-
"""Less than or equal to the specified value."""
4865-
lessThanOrEqualTo: BigFloat
4866-
4867-
"""Greater than the specified value."""
4868-
greaterThan: BigFloat
4869-
4870-
"""Greater than or equal to the specified value."""
4871-
greaterThanOrEqualTo: BigFloat
4872-
}
4873-
4874-
"""
4875-
A floating point number that requires more precision than IEEE 754 binary 64
4876-
"""
4877-
scalar BigFloat
4878-
48794879
input TokenRetiredDistinctCountAggregateFilter {
48804880
aid: BigIntFilter
48814881
id: BigIntFilter
@@ -7055,7 +7055,7 @@ input EvaluationCondition {
70557055
status: Int
70567056

70577057
"""Checks for equality with the object’s `reason` field."""
7058-
reason: Int
7058+
reason: BigFloat
70597059

70607060
"""Checks for equality with the object’s `verificationProof` field."""
70617061
verificationProof: String

src/graphql/bigint_plugin.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// import { GraphQLScalarType } from "graphql";
2+
// import { Plugin } from "graphile-build";
3+
4+
// // Create a custom scalar (with a different name to avoid conflict)
5+
// const SmartNumericType = new GraphQLScalarType({
6+
// name: "SmartNumeric", // Different name to avoid conflict with BigInt
7+
// description: "Custom scalar type for handling NUMERIC values intelligently",
8+
9+
// // Convert outgoing values (DB to client)
10+
// serialize(value) {
11+
// console.log("SmartNumeric serialize called with:", value);
12+
// if (value === null) return null;
13+
// // Return as number if within safe integer range, otherwise as string
14+
// const num = Number(value);
15+
// return Number.isSafeInteger(num) ? num : value.toString();
16+
// },
17+
18+
// // Convert incoming values (client to DB)
19+
// parseValue(value) {
20+
// console.log("SmartNumeric parseValue called with:", value);
21+
// if (value === null) return null;
22+
// if (typeof value === "string") {
23+
// const num = Number(value);
24+
// if (Number.isNaN(num)) {
25+
// throw new Error(
26+
// "SmartNumeric cannot represent non-numeric value: " + value
27+
// );
28+
// }
29+
// return num;
30+
// }
31+
// if (typeof value === "number") {
32+
// if (!Number.isFinite(value)) {
33+
// throw new Error(
34+
// "SmartNumeric cannot represent non-finite value: " + value
35+
// );
36+
// }
37+
// return value;
38+
// }
39+
// throw new Error(
40+
// "SmartNumeric cannot represent non-numeric value: " + value
41+
// );
42+
// },
43+
44+
// // Convert incoming literal values in queries
45+
// parseLiteral(ast) {
46+
// console.log("SmartNumeric parseLiteral called");
47+
// if (ast.kind === "IntValue" || ast.kind === "FloatValue") {
48+
// const num = Number(ast.value);
49+
// if (Number.isNaN(num)) {
50+
// throw new Error(
51+
// "SmartNumeric cannot represent non-numeric value: " + ast.value
52+
// );
53+
// }
54+
// return num;
55+
// }
56+
// if (ast.kind === "StringValue") {
57+
// const num = Number(ast.value);
58+
// if (Number.isNaN(num)) {
59+
// throw new Error(
60+
// "SmartNumeric cannot represent non-numeric value: " + ast.value
61+
// );
62+
// }
63+
// return num;
64+
// }
65+
// throw new Error(
66+
// "SmartNumeric cannot represent non-numeric value: " + ast.kind
67+
// );
68+
// },
69+
// });
70+
71+
// // Plugin to override how numeric fields are handled
72+
// export const SmartNumericPlugin: Plugin = (builder) => {
73+
// // First add our custom scalar type
74+
// builder.hook("build", (build) => {
75+
// build.addType(SmartNumericType);
76+
// return build;
77+
// });
78+
79+
// // Then add a hook to intercept numeric fields and replace with our custom scalar
80+
// builder.hook("GraphQLObjectType:fields:field", (field, build, context) => {
81+
// const {
82+
// scope: { pgFieldIntrospection },
83+
// } = context;
84+
85+
// // Skip if this isn't a PostgreSQL field
86+
// if (!pgFieldIntrospection) {
87+
// return field;
88+
// }
89+
90+
// // Check if this is a numeric field from ClaimCollection
91+
// if (
92+
// // pgFieldIntrospection.type.name === "numeric" &&
93+
// // pgFieldIntrospection.class &&
94+
// // pgFieldIntrospection.class.name === "ClaimCollection" &&
95+
// // [
96+
// // "quota",
97+
// // "count",
98+
// // "evaluated",
99+
// // "approved",
100+
// // "rejected",
101+
// // "disputed",
102+
// // "invalidated",
103+
// // ].includes(pgFieldIntrospection.name)
104+
// pgFieldIntrospection.type.name === "numeric"
105+
// ) {
106+
// console.log(
107+
// `Replacing field ${pgFieldIntrospection.name} with SmartNumeric type`
108+
// );
109+
110+
// // Replace the type with our custom scalar
111+
// return {
112+
// ...field,
113+
// type: SmartNumericType,
114+
// };
115+
// }
116+
117+
// return field;
118+
// });
119+
// };
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Up Migration
2+
3+
-- Altering columns with type uint64 on chain to type numeric
4+
5+
ALTER TABLE "ClaimCollection"
6+
ALTER COLUMN "quota" TYPE NUMERIC USING quota::NUMERIC,
7+
ALTER COLUMN "count" TYPE NUMERIC USING count::NUMERIC,
8+
ALTER COLUMN "evaluated" TYPE NUMERIC USING evaluated::NUMERIC,
9+
ALTER COLUMN "approved" TYPE NUMERIC USING approved::NUMERIC,
10+
ALTER COLUMN "rejected" TYPE NUMERIC USING rejected::NUMERIC,
11+
ALTER COLUMN "disputed" TYPE NUMERIC USING disputed::NUMERIC,
12+
ALTER COLUMN "invalidated" TYPE NUMERIC USING invalidated::NUMERIC;
13+
14+
ALTER TABLE "Evaluation"
15+
ALTER COLUMN "reason" TYPE NUMERIC USING reason::NUMERIC;
16+
17+
-- Down Migration

0 commit comments

Comments
 (0)