The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix core client JSON scalar types (#28281)
Weiko47924e8f71dd
diff --git a/packages/twenty-client-sdk/src/generate/__tests__/generated-client-query.test.ts b/packages/twenty-client-sdk/src/generate/__tests__/generated-client-query.test.tsindex c2c0c737862..c1b9b5cfd46 100644--- a/packages/twenty-client-sdk/src/generate/__tests__/generated-client-query.test.ts+++ b/packages/twenty-client-sdk/src/generate/__tests__/generated-client-query.test.ts@@ -1,8 +1,13 @@-import { mkdtemp, rm } from 'node:fs/promises';+import { mkdtemp, rm, writeFile } from 'node:fs/promises';import { tmpdir } from 'node:os';import { join } from 'node:path';import { pathToFileURL } from 'node:url';+import {+ createProgram,+ flattenDiagnosticMessageText,+ getPreEmitDiagnostics,+} from 'typescript';import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';import { generateCoreClientFromSchema } from '../generate-core-client';@@ -13,6 +18,8 @@ import { generateCoreClientFromSchema } from '../generate-core-client';// client-wrapper-auth.test.ts, which stubs createClient and so never runs the// vendored runtime's query-building path.const SCHEMA = `+scalar JSON+type Query {hello: Stringperson(id: ID!): Person@@ -20,6 +27,11 @@ type Query {type Mutation {createPerson(name: String!): Person+ createCallRecording(data: CallRecordingCreateInput!): String+}++input CallRecordingCreateInput {+ transcript: JSON}type Person {@@ -72,6 +84,37 @@ describe('Generated client queries the API (vendored genql runtime)', () => {}});+ it('accepts arrays and primitive JSON values in generated mutation inputs', async () => {+ const fixturePath = join(temporaryDir, 'json-input.ts');++ await writeFile(+ fixturePath,+ `import { type CallRecordingCreateInput } from './client/schema';++const inputs = [+ { transcript: [{ speaker: 'Ada', text: 'Hello' }] },+ { transcript: { text: 'Hello' } },+ { transcript: 'Hello' },+ { transcript: 42 },+ { transcript: true },+ { transcript: null },+] satisfies CallRecordingCreateInput[];+`,+ );++ const program = createProgram([fixturePath], {+ noEmit: true,+ strict: true,+ skipLibCheck: true,+ types: [],+ });+ const diagnostics = getPreEmitDiagnostics(program).map((diagnostic) =>+ flattenDiagnosticMessageText(diagnostic.messageText, '\n'),+ );++ expect(diagnostics).toEqual([]);+ });+it('builds a GraphQL query from a selection and returns parsed data', async () => {const fetchMock = vi.fn(async (_url: string, _init?: RequestInit) =>jsonResponse({ data: { person: { id: '1', name: 'Ada' } } }),diff --git a/packages/twenty-client-sdk/src/generate/generate-core-client.ts b/packages/twenty-client-sdk/src/generate/generate-core-client.tsindex b293701f4cb..01a2f22f44a 100644--- a/packages/twenty-client-sdk/src/generate/generate-core-client.ts+++ b/packages/twenty-client-sdk/src/generate/generate-core-client.ts@@ -11,7 +11,7 @@ import twentyClientTemplateSource from './twenty-client-template.ts?raw';const COMMON_SCALAR_TYPES = {DateTime: 'string',- JSON: 'Record<string, unknown>',+ JSON: 'unknown',UUID: 'string',};