Skip to content

Commit

Permalink
feat(typegen): set overload client methods to default to true (#7390)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth authored and cngonzalez committed Aug 20, 2024
1 parent e21bf08 commit 93d49a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema": "./working-schema.json",
"generates": "./out/types.ts",
"overloadClientMethods": true
"overloadClientMethods": false
}
18 changes: 9 additions & 9 deletions packages/@sanity/cli/test/__snapshots__/typegen.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}
"
`;
4 changes: 2 additions & 2 deletions packages/@sanity/cli/test/typegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -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()
})
})
2 changes: 1 addition & 1 deletion packages/@sanity/codegen/src/readConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof configDefintion>
Expand Down

0 comments on commit 93d49a7

Please sign in to comment.