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

Typescript BigInt support (In Progress) #11730

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import humanize from 'humanize-string'

const MAX_STRING_LENGTH = 150

export const bigIntDisplay = (value: bigint) => {
return value.toString()
}

export const formatEnum = (values: string | string[] | null | undefined) => {
let output = ''

Expand All @@ -25,7 +29,7 @@ export const jsonDisplay = (obj: unknown) => {
)
}

export const truncate = (value: string | number) => {
export const truncate = (value: string | number | bigint) => {
let output = value?.toString() ?? ''

if (output.length > MAX_STRING_LENGTH) {
Expand Down
6 changes: 5 additions & 1 deletion __fixtures__/test-project/web/src/lib/formatters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import humanize from 'humanize-string'

const MAX_STRING_LENGTH = 150

export const bigIntDisplay = (value: bigint) => {
return value.toString()
}

export const formatEnum = (values: string | string[] | null | undefined) => {
let output = ''

Expand All @@ -25,7 +29,7 @@ export const jsonDisplay = (obj: unknown) => {
)
}

export const truncate = (value: string | number) => {
export const truncate = (value: string | number | bigint) => {
let output = value?.toString() ?? ''

if (output.length > MAX_STRING_LENGTH) {
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/commands/generate/scaffold/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ const modelRelatedVariables = (model) => {
listDisplayFunction: 'formatEnum',
displayFunction: 'formatEnum',
},
BigInt: {
componentName: 'TextField',
displayFunction: 'bigIntDisplay',
listDisplayFunction: 'truncate',
},
Boolean: {
componentName: 'CheckboxField',
defaultProp: 'defaultChecked',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import humanize from 'humanize-string'

const MAX_STRING_LENGTH = 150

export const bigIntDisplay = (value: bigint) => {
return value.toString()
}

export const formatEnum = (values: string | string[] | null | undefined) => {
let output = ''

Expand All @@ -25,7 +29,7 @@ export const jsonDisplay = (obj: unknown) => {
)
}

export const truncate = (value: string | number) => {
export const truncate = (value: string | number | bigint) => {
let output = value?.toString() ?? ''

if (output.length > MAX_STRING_LENGTH) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type Scalars = {
Boolean: boolean;
Int: number;
Float: number;
BigInt: number;
BigInt: bigint;
Byte: Buffer;
Date: Date | string;
DateTime: Date | string;
Expand Down Expand Up @@ -328,7 +328,7 @@ export type Scalars = {
Boolean: boolean;
Int: number;
Float: number;
BigInt: number;
BigInt: bigint;
Byte: Buffer;
Date: string;
DateTime: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Scalars = {
Boolean: boolean;
Int: number;
Float: number;
BigInt: number;
BigInt: bigint;
Date: string;
DateTime: string;
JSON: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Scalars = {
Boolean: boolean;
Int: number;
Float: number;
BigInt: number;
BigInt: bigint;
Date: string;
DateTime: string;
JSON: Record<string, unknown>;
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/src/generate/graphqlCodeGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async function getPluginConfig(side: CodegenSide) {
| 'File'
const scalars: Partial<Record<ScalarKeys, string>> = {
// We need these, otherwise these scalars are mapped to any
BigInt: 'number',
BigInt: 'bigint',
// @Note: DateTime fields can be valid Date-strings, or the Date object in the api side. They're always strings on the web side.
DateTime: side === CodegenSide.WEB ? 'string' : 'Date | string',
Date: side === CodegenSide.WEB ? 'string' : 'Date | string',
Expand Down
Loading