From eb4271ac81e97290ab237addebca4a06669e8586 Mon Sep 17 00:00:00 2001 From: Curtis Reimer Date: Fri, 1 Nov 2024 17:46:11 -0500 Subject: [PATCH 1/3] initial dev --- .../src/__tests__/__snapshots__/graphqlCodeGen.test.ts.snap | 4 ++-- .../internal/src/__tests__/fixtures/api/types/graphql.d.ts | 2 +- .../internal/src/__tests__/fixtures/web/types/graphql.d.ts | 2 +- packages/internal/src/generate/graphqlCodeGen.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/internal/src/__tests__/__snapshots__/graphqlCodeGen.test.ts.snap b/packages/internal/src/__tests__/__snapshots__/graphqlCodeGen.test.ts.snap index 8f20d42df52f..0bc05551268b 100644 --- a/packages/internal/src/__tests__/__snapshots__/graphqlCodeGen.test.ts.snap +++ b/packages/internal/src/__tests__/__snapshots__/graphqlCodeGen.test.ts.snap @@ -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; @@ -328,7 +328,7 @@ export type Scalars = { Boolean: boolean; Int: number; Float: number; - BigInt: number; + BigInt: bigint; Byte: Buffer; Date: string; DateTime: string; diff --git a/packages/internal/src/__tests__/fixtures/api/types/graphql.d.ts b/packages/internal/src/__tests__/fixtures/api/types/graphql.d.ts index d2e76e788bc0..dd41319fc178 100644 --- a/packages/internal/src/__tests__/fixtures/api/types/graphql.d.ts +++ b/packages/internal/src/__tests__/fixtures/api/types/graphql.d.ts @@ -11,7 +11,7 @@ export type Scalars = { Boolean: boolean; Int: number; Float: number; - BigInt: number; + BigInt: bigint; Date: string; DateTime: string; JSON: Record; diff --git a/packages/internal/src/__tests__/fixtures/web/types/graphql.d.ts b/packages/internal/src/__tests__/fixtures/web/types/graphql.d.ts index 2ceabf283616..adac0872d6a5 100644 --- a/packages/internal/src/__tests__/fixtures/web/types/graphql.d.ts +++ b/packages/internal/src/__tests__/fixtures/web/types/graphql.d.ts @@ -10,7 +10,7 @@ export type Scalars = { Boolean: boolean; Int: number; Float: number; - BigInt: number; + BigInt: bigint; Date: string; DateTime: string; JSON: Record; diff --git a/packages/internal/src/generate/graphqlCodeGen.ts b/packages/internal/src/generate/graphqlCodeGen.ts index ec3f8b43c451..eb9bb4d74b20 100644 --- a/packages/internal/src/generate/graphqlCodeGen.ts +++ b/packages/internal/src/generate/graphqlCodeGen.ts @@ -285,7 +285,7 @@ async function getPluginConfig(side: CodegenSide) { | 'File' const scalars: Partial> = { // 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', From 9c4d477954733cb58ba288030c83b17875b97f81 Mon Sep 17 00:00:00 2001 From: Curtis Reimer Date: Wed, 20 Nov 2024 17:04:54 -0600 Subject: [PATCH 2/3] added bigint to formatters --- .../test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx | 2 +- __fixtures__/test-project/web/src/lib/formatters.tsx | 2 +- .../generate/scaffold/templates/lib/formatters.tsx.template | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx b/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx index 8ab9e806e3cd..8e5c4376186d 100644 --- a/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx +++ b/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx @@ -25,7 +25,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) { diff --git a/__fixtures__/test-project/web/src/lib/formatters.tsx b/__fixtures__/test-project/web/src/lib/formatters.tsx index 8ab9e806e3cd..8e5c4376186d 100644 --- a/__fixtures__/test-project/web/src/lib/formatters.tsx +++ b/__fixtures__/test-project/web/src/lib/formatters.tsx @@ -25,7 +25,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) { diff --git a/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template index 8ab9e806e3cd..8e5c4376186d 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template @@ -25,7 +25,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) { From 52352fc068f95efe22c0c359b618c3020caaa358 Mon Sep 17 00:00:00 2001 From: Curtis Reimer Date: Wed, 20 Nov 2024 17:57:15 -0600 Subject: [PATCH 3/3] progress --- .../test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx | 4 ++++ __fixtures__/test-project/web/src/lib/formatters.tsx | 4 ++++ packages/cli/src/commands/generate/scaffold/scaffold.js | 5 +++++ .../generate/scaffold/templates/lib/formatters.tsx.template | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx b/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx index 8e5c4376186d..e72dbeb5c221 100644 --- a/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx +++ b/__fixtures__/test-project-rsc-kitchen-sink/web/src/lib/formatters.tsx @@ -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 = '' diff --git a/__fixtures__/test-project/web/src/lib/formatters.tsx b/__fixtures__/test-project/web/src/lib/formatters.tsx index 8e5c4376186d..e72dbeb5c221 100644 --- a/__fixtures__/test-project/web/src/lib/formatters.tsx +++ b/__fixtures__/test-project/web/src/lib/formatters.tsx @@ -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 = '' diff --git a/packages/cli/src/commands/generate/scaffold/scaffold.js b/packages/cli/src/commands/generate/scaffold/scaffold.js index ed0beb58da06..509e62e7966c 100644 --- a/packages/cli/src/commands/generate/scaffold/scaffold.js +++ b/packages/cli/src/commands/generate/scaffold/scaffold.js @@ -306,6 +306,11 @@ const modelRelatedVariables = (model) => { listDisplayFunction: 'formatEnum', displayFunction: 'formatEnum', }, + BigInt: { + componentName: 'TextField', + displayFunction: 'bigIntDisplay', + listDisplayFunction: 'truncate', + }, Boolean: { componentName: 'CheckboxField', defaultProp: 'defaultChecked', diff --git a/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template index 8e5c4376186d..e72dbeb5c221 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/lib/formatters.tsx.template @@ -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 = ''