Skip to content

Commit c11e51f

Browse files
authored
feat(typegen): set overload client methods to default to true (#7390)
1 parent b86e3d0 commit c11e51f

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"schema": "./working-schema.json",
33
"generates": "./out/types.ts",
4-
"overloadClientMethods": true
4+
"overloadClientMethods": false
55
}

packages/@sanity/cli/test/__snapshots__/typegen.test.ts.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ export declare const internalGroqTypeReferenceTo: unique symbol;
3838
// Variable: PAGE_QUERY
3939
// Query: *[_type == \\"page\\" && slug.current == $slug][0]
4040
export type PAGE_QUERYResult = null;
41+
42+
// Query TypeMap
43+
import '@sanity/client';
44+
declare module '@sanity/client' {
45+
interface SanityQueries {
46+
'*[_type == \\"page\\" && slug.current == $slug][0]': PAGE_QUERYResult;
47+
}
48+
}
4149
"
4250
`;
4351

44-
exports[`CLI: \`sanity typegen\` sanity typegen generate: with overloadClientMethods 1`] = `
52+
exports[`CLI: \`sanity typegen\` sanity typegen generate: with overloadClientMethods false 1`] = `
4553
"/**
4654
* ---------------------------------------------------------------------------------
4755
* This file has been generated by Sanity TypeGen.
@@ -79,13 +87,5 @@ export declare const internalGroqTypeReferenceTo: unique symbol;
7987
// Variable: PAGE_QUERY
8088
// Query: *[_type == \\"page\\" && slug.current == $slug][0]
8189
export type PAGE_QUERYResult = null;
82-
83-
// Query TypeMap
84-
import '@sanity/client';
85-
declare module '@sanity/client' {
86-
interface SanityQueries {
87-
'*[_type == \\"page\\" && slug.current == $slug][0]': PAGE_QUERYResult;
88-
}
89-
}
9090
"
9191
`;

packages/@sanity/cli/test/typegen.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describeCliTest('CLI: `sanity typegen`', () => {
7070
expect(types.toString()).toMatchSnapshot()
7171
})
7272

73-
test('sanity typegen generate: with overloadClientMethods', async () => {
73+
test('sanity typegen generate: with overloadClientMethods false', async () => {
7474
// Write a prettier config to the output folder, with single quotes. The defeault is double quotes.
7575
await writeFile(`${studiosPath}/v3/out/.prettierrc`, '{\n "singleQuote": true\n}\n')
7676
const result = await runSanityCmdCommand('v3', [
@@ -86,7 +86,7 @@ describeCliTest('CLI: `sanity typegen`', () => {
8686
)
8787

8888
const types = await readFile(`${studiosPath}/v3/out/types.ts`)
89-
expect(types.toString()).toContain(`'person'`)
89+
expect(types.toString()).not.toContain(`Query TypeMap`)
9090
expect(types.toString()).toMatchSnapshot()
9191
})
9292
})

packages/@sanity/codegen/src/readConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const configDefintion = z.object({
1515
schema: z.string().default('./schema.json'),
1616
generates: z.string().default('./sanity.types.ts'),
1717
formatGeneratedCode: z.boolean().default(true),
18-
overloadClientMethods: z.boolean().default(false),
18+
overloadClientMethods: z.boolean().default(true),
1919
})
2020

2121
export type CodegenConfig = z.infer<typeof configDefintion>

0 commit comments

Comments
 (0)