From 93d49a74b78d7ccbdd9d6494f6af8082eee5b085 Mon Sep 17 00:00:00 2001 From: Sindre Gulseth Date: Tue, 20 Aug 2024 12:16:18 +0200 Subject: [PATCH] feat(typegen): set overload client methods to default to true (#7390) --- .../working-typegen-overloadClientMethods.json | 2 +- .../test/__snapshots__/typegen.test.ts.snap | 18 +++++++++--------- packages/@sanity/cli/test/typegen.test.ts | 4 ++-- packages/@sanity/codegen/src/readConfig.ts | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/@sanity/cli/test/__fixtures__/v3/working-typegen-overloadClientMethods.json b/packages/@sanity/cli/test/__fixtures__/v3/working-typegen-overloadClientMethods.json index 0ad1ab7f47f..959b1a55b31 100644 --- a/packages/@sanity/cli/test/__fixtures__/v3/working-typegen-overloadClientMethods.json +++ b/packages/@sanity/cli/test/__fixtures__/v3/working-typegen-overloadClientMethods.json @@ -1,5 +1,5 @@ { "schema": "./working-schema.json", "generates": "./out/types.ts", - "overloadClientMethods": true + "overloadClientMethods": false } diff --git a/packages/@sanity/cli/test/__snapshots__/typegen.test.ts.snap b/packages/@sanity/cli/test/__snapshots__/typegen.test.ts.snap index a8ea1d74606..c26bbf6b2bb 100644 --- a/packages/@sanity/cli/test/__snapshots__/typegen.test.ts.snap +++ b/packages/@sanity/cli/test/__snapshots__/typegen.test.ts.snap @@ -38,10 +38,18 @@ export declare const internalGroqTypeReferenceTo: unique symbol; // Variable: PAGE_QUERY // Query: *[_type == \\"page\\" && slug.current == $slug][0] export type PAGE_QUERYResult = null; + +// Query TypeMap +import '@sanity/client'; +declare module '@sanity/client' { + interface SanityQueries { + '*[_type == \\"page\\" && slug.current == $slug][0]': PAGE_QUERYResult; + } +} " `; -exports[`CLI: \`sanity typegen\` sanity typegen generate: with overloadClientMethods 1`] = ` +exports[`CLI: \`sanity typegen\` sanity typegen generate: with overloadClientMethods false 1`] = ` "/** * --------------------------------------------------------------------------------- * This file has been generated by Sanity TypeGen. @@ -79,13 +87,5 @@ export declare const internalGroqTypeReferenceTo: unique symbol; // Variable: PAGE_QUERY // Query: *[_type == \\"page\\" && slug.current == $slug][0] export type PAGE_QUERYResult = null; - -// Query TypeMap -import '@sanity/client'; -declare module '@sanity/client' { - interface SanityQueries { - '*[_type == \\"page\\" && slug.current == $slug][0]': PAGE_QUERYResult; - } -} " `; diff --git a/packages/@sanity/cli/test/typegen.test.ts b/packages/@sanity/cli/test/typegen.test.ts index 96c0b7a7890..d47a6ccb590 100644 --- a/packages/@sanity/cli/test/typegen.test.ts +++ b/packages/@sanity/cli/test/typegen.test.ts @@ -70,7 +70,7 @@ describeCliTest('CLI: `sanity typegen`', () => { expect(types.toString()).toMatchSnapshot() }) - test('sanity typegen generate: with overloadClientMethods', async () => { + test('sanity typegen generate: with overloadClientMethods false', async () => { // Write a prettier config to the output folder, with single quotes. The defeault is double quotes. await writeFile(`${studiosPath}/v3/out/.prettierrc`, '{\n "singleQuote": true\n}\n') const result = await runSanityCmdCommand('v3', [ @@ -86,7 +86,7 @@ describeCliTest('CLI: `sanity typegen`', () => { ) const types = await readFile(`${studiosPath}/v3/out/types.ts`) - expect(types.toString()).toContain(`'person'`) + expect(types.toString()).not.toContain(`Query TypeMap`) expect(types.toString()).toMatchSnapshot() }) }) diff --git a/packages/@sanity/codegen/src/readConfig.ts b/packages/@sanity/codegen/src/readConfig.ts index 082130b56f8..3f9f6f3c030 100644 --- a/packages/@sanity/codegen/src/readConfig.ts +++ b/packages/@sanity/codegen/src/readConfig.ts @@ -15,7 +15,7 @@ export const configDefintion = z.object({ schema: z.string().default('./schema.json'), generates: z.string().default('./sanity.types.ts'), formatGeneratedCode: z.boolean().default(true), - overloadClientMethods: z.boolean().default(false), + overloadClientMethods: z.boolean().default(true), }) export type CodegenConfig = z.infer