Skip to content

Commit 7402093

Browse files
authoredMar 20, 2024
fix(codegen): uppercase query type names (#6080)
1 parent 2e06b84 commit 7402093

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed
 

‎packages/@sanity/codegen/src/typescript/__tests__/__snapshots__/typeGenerator.test.ts.snap

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
exports[`generateSchemaTypes can generate well known types 1`] = `"export declare const internalGroqTypeReferenceTo: unique symbol;"`;
44

5-
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: boolean 1`] = `"export type test_2 = boolean;"`;
5+
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: boolean 1`] = `"export type Test_2 = boolean;"`;
66

7-
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: null 1`] = `"export type test_5 = null;"`;
7+
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: null 1`] = `"export type Test_5 = null;"`;
88

9-
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: number 1`] = `"export type test_3 = number;"`;
9+
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: number 1`] = `"export type Test_3 = number;"`;
1010

11-
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: string 1`] = `"export type test = string;"`;
11+
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: string 1`] = `"export type Test = string;"`;
1212

13-
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: unknown 1`] = `"export type test_4 = unknown;"`;
13+
exports[`generateSchemaTypes generateTypeNodeTypes should be able to generate types for type nodes: unknown 1`] = `"export type Test_4 = unknown;"`;
1414

1515
exports[`generateSchemaTypes should generate TypeScript type declarations for a schema 1`] = `
1616
"export type Author = {
@@ -212,7 +212,7 @@ export type SanityImagePaletteSwatch = {
212212
`;
213213

214214
exports[`generateSchemaTypes should generate correct types for document schema with inline fields 1`] = `
215-
"export type myObject = {
215+
"export type MyObject = {
216216
inlineField: {
217217
test: string;
218218
} & Test;
@@ -224,4 +224,4 @@ exports[`generateSchemaTypes should generate correct types for document schema w
224224
};"
225225
`;
226226
227-
exports[`generateSchemaTypes should generate correct types for document schema with inline fields 2`] = `"export type someOtherType = MyObject;"`;
227+
exports[`generateSchemaTypes should generate correct types for document schema with inline fields 2`] = `"export type SomeOtherType = MyObject;"`;

‎packages/@sanity/codegen/src/typescript/__tests__/typeGenerator.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export type Author = {
399399
const objectNodeOut = typeGenerator.generateTypeNodeTypes('myObject', objectNode)
400400
expect(objectNodeOut).toMatchSnapshot()
401401

402-
const someOtherTypeOut = typeGenerator.generateTypeNodeTypes('someOtherType', {
402+
const someOtherTypeOut = typeGenerator.generateTypeNodeTypes('SomeOtherType', {
403403
type: 'inline',
404404
name: 'myObject',
405405
})

‎packages/@sanity/codegen/src/typescript/typeGenerator.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class TypeGenerator {
4141
const typeLiteral = this.getTypeNodeType(schema)
4242

4343
const typeAlias = t.tsTypeAliasDeclaration(
44-
t.identifier(this.getTypeName(schema.name, true)),
44+
t.identifier(this.getTypeName(schema.name)),
4545
null,
4646
typeLiteral,
4747
)
@@ -65,7 +65,7 @@ export class TypeGenerator {
6565
const type = this.getTypeNodeType(typeNode)
6666

6767
const typeAlias = t.tsTypeAliasDeclaration(
68-
t.identifier(this.getTypeName(identifierName, false)),
68+
t.identifier(this.getTypeName(identifierName)),
6969
null,
7070
type,
7171
)
@@ -90,10 +90,8 @@ export class TypeGenerator {
9090
* types would be sanityized into MuxVideo. To avoid this we keep track of the generated type names and add a index to the name.
9191
* When we reference a type we also keep track of the original name so we can reference the correct type later.
9292
*/
93-
private getTypeName(name: string, shouldUppercaseFirstLetter: boolean): string {
94-
const desiredName = shouldUppercaseFirstLetter
95-
? uppercaseFirstLetter(sanitizeIdentifier(name))
96-
: sanitizeIdentifier(name)
93+
private getTypeName(name: string): string {
94+
const desiredName = uppercaseFirstLetter(sanitizeIdentifier(name))
9795

9896
let generatedName = desiredName
9997
let i = 2

0 commit comments

Comments
 (0)