Skip to content

Commit 0573bd7

Browse files
committed
feat: update JSON serialization for LiteralValue to handle bigint values
1 parent 2fd3fb0 commit 0573bd7

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/extraction/getTypeFromValue.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ export const getTypeFromValue = (
99
value?: LiteralValue | null,
1010
dataTypes?: DataType[]
1111
): string => {
12+
13+
1214
// 1. Serialize value to a JSON string for embedding in source code.
13-
const literal = JSON.stringify(value?.value);
15+
const literal = JSON.stringify(value?.value, (key, val) =>
16+
typeof val === 'bigint' ? val.toString() : val
17+
)
1418

1519
if (!literal) return "any"
1620

src/utils.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ export function generateFlowSourceCode(
125125
});
126126
return `/* @pos ${nodeId} ${paramIdx} */ ${refCode}`;
127127
}
128-
if (val.__typename === "LiteralValue") return `/* @pos ${nodeId} ${paramIdx} */ ${JSON.stringify(val.value)}`;
128+
if (val.__typename === "LiteralValue") {
129+
const jsonString = JSON.stringify(val?.value, (key, val) =>
130+
typeof val === 'bigint' ? val.toString() : val
131+
)
132+
return `/* @pos ${nodeId} ${paramIdx} */ ${jsonString}`;
133+
}
129134
if (val.__typename === "NodeFunctionIdWrapper") {
130135
const wrapper = val as NodeFunctionIdWrapper;
131136
return generateNodeCall(wrapper.id!, nodeId, paramIdx);
@@ -172,7 +177,12 @@ export function generateFlowSourceCode(
172177
});
173178
return `/* @pos ${nodeId} ${index} */ ${refCode}`;
174179
}
175-
if (val.__typename === "LiteralValue") return `/* @pos ${nodeId} ${index} */ ${JSON.stringify(val.value)}`;
180+
if (val.__typename === "LiteralValue") {
181+
const jsonString = JSON.stringify(val?.value, (key, val) =>
182+
typeof val === 'bigint' ? val.toString() : val
183+
)
184+
return `/* @pos ${nodeId} ${index} */ ${jsonString}`;
185+
}
176186
if (val.__typename === "NodeFunctionIdWrapper") {
177187
const wrapper = val as NodeFunctionIdWrapper;
178188

src/validation/getValueValidation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import ts from "typescript";
22
import {DataType, LiteralValue} from "@code0-tech/sagittarius-graphql-types";
33
import {createCompilerHost, getSharedTypeDeclarations, ValidationResult} from "../utils";
44

5+
56
export const getValueValidation = (
67
type?: string,
78
value?: LiteralValue,
89
dataTypes?: DataType[]
910
): ValidationResult => {
10-
const valueAsCode = JSON.stringify(value?.value);
11+
12+
const jsonString = JSON.stringify(value?.value, (key, val) =>
13+
typeof val === 'bigint' ? val.toString() : val
14+
)
1115

1216
// 1. Construct the source code for validation.
1317
const sourceCode = `
1418
${getSharedTypeDeclarations(dataTypes)}
15-
const testValue: ${type} = ${valueAsCode};
19+
const testValue: ${type} = ${jsonString};
1620
`;
1721

1822
const fileName = "index.ts";

0 commit comments

Comments
 (0)