Skip to content

Commit a4248e4

Browse files
committed
Remove dead code from type-utils.ts
Remove unused utility functions that were superseded by the mutation engine: - getTemplatedModelName (mutation engine handles template naming) - getSingleNameWithNamespace (never used in production) - isArray, isRecordType, isScalarOrEnumArray, isUnionArray (use compiler's isArrayModelType) - unwrapModel, unwrapType (never imported) - isTrueModel (never imported) Also removes the corresponding test for getSingleNameWithNamespace.
1 parent 157e529 commit a4248e4

2 files changed

Lines changed: 0 additions & 100 deletions

File tree

packages/graphql/src/lib/type-utils.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import {
2-
type ArrayModelType,
3-
type Enum,
42
getDoc,
53
getTypeName,
64
type IndeterminateEntity,
7-
isNeverType,
85
isNullType,
96
isTemplateInstance,
10-
type Model,
117
type Program,
12-
type RecordModelType,
13-
type Scalar,
148
type Type,
159
type Union,
1610
type UnionVariant,
1711
type Value,
18-
walkPropertiesInherited,
1912
} from "@typespec/compiler";
2013
import {
2114
type AliasStatementNode,
@@ -75,14 +68,6 @@ export function stripNullVariants(union: Union): {
7568
};
7669
}
7770

78-
/** Generate a GraphQL type name for a templated model (e.g., `ListOfString`). */
79-
export function getTemplatedModelName(model: Model): string {
80-
const name = getTypeName(model, {});
81-
const baseName = toTypeName(name.replace(/<[^>]*>/g, ""));
82-
const templateString = getTemplateString(model);
83-
return templateString ? `${baseName}Of${templateString}` : baseName;
84-
}
85-
8671
function splitWithAcronyms(
8772
splitFn: (name: string) => string[],
8873
skipStart: boolean,
@@ -233,64 +218,6 @@ function getUnionNameForOperation(program: Program, union: Union): string {
233218
return toTypeName(getTypeName(operation));
234219
}
235220

236-
/** Convert a namespaced name to a single name by replacing dots with underscores. */
237-
export function getSingleNameWithNamespace(name: string): string {
238-
return name.trim().replace(/\./g, "_");
239-
}
240-
241-
/**
242-
* Check if a model is an array type.
243-
*/
244-
export function isArray(model: Model): model is ArrayModelType {
245-
return Boolean(model.indexer && model.indexer.key.name === "integer");
246-
}
247-
248-
/**
249-
* Check if a model is a record/map type.
250-
*/
251-
export function isRecordType(type: Model): type is RecordModelType {
252-
return Boolean(type.indexer && type.indexer.key.name === "string");
253-
}
254-
255-
/** Check if a model is an array of scalars or enums. */
256-
export function isScalarOrEnumArray(type: Model): type is ArrayModelType {
257-
return (
258-
isArray(type) && (type.indexer?.value.kind === "Scalar" || type.indexer?.value.kind === "Enum")
259-
);
260-
}
261-
262-
/** Check if a model is an array of unions. */
263-
export function isUnionArray(type: Model): type is ArrayModelType {
264-
return isArray(type) && type.indexer?.value.kind === "Union";
265-
}
266-
267-
/** Extract the element type from an array model, or return the model itself. */
268-
export function unwrapModel(model: ArrayModelType): Model | Scalar | Enum | Union;
269-
export function unwrapModel(model: Exclude<Model, ArrayModelType>): Model;
270-
export function unwrapModel(model: Model): Model | Scalar | Enum | Union {
271-
if (!isArray(model)) {
272-
return model;
273-
}
274-
275-
if (model.indexer?.value.kind) {
276-
if (["Model", "Scalar", "Enum", "Union"].includes(model.indexer.value.kind)) {
277-
return model.indexer.value as Model | Scalar | Enum | Union;
278-
}
279-
throw new Error(`Unexpected array type: ${model.indexer.value.kind}`);
280-
}
281-
return model;
282-
}
283-
284-
/** Unwrap array types to get the inner element type. */
285-
export function unwrapType(type: Model): Model | Scalar | Enum | Union;
286-
export function unwrapType(type: Type): Type;
287-
export function unwrapType(type: Type): Type {
288-
if (type.kind === "Model") {
289-
return unwrapModel(type);
290-
}
291-
return type;
292-
}
293-
294221
/** Get the GraphQL description for a type from its doc comments. */
295222
export function getGraphQLDoc(program: Program, type: Type): string | undefined {
296223
// GraphQL uses CommonMark for descriptions
@@ -318,15 +245,3 @@ function getTemplateStringInternal(
318245
return args.length > 0 ? args.map(toTypeName).join(options.conjunction) : "";
319246
}
320247

321-
/** Check if a model should be emitted as a GraphQL object type (not an array, record, or never). */
322-
export function isTrueModel(model: Model): boolean {
323-
return !(
324-
// Array of scalars/enums — represented as a list type, not an object type
325-
isScalarOrEnumArray(model) ||
326-
// Array of unions — represented as a list type, not an object type
327-
isUnionArray(model) ||
328-
isNeverType(model) ||
329-
// Pure record with no properties — emitted as a custom scalar, not an object type
330-
(isRecordType(model) && [...walkPropertiesInherited(model)].length === 0)
331-
);
332-
}

packages/graphql/test/lib/type-utils.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it } from "vitest";
22
import {
3-
getSingleNameWithNamespace,
43
sanitizeNameForGraphQL,
54
toEnumMemberName,
65
toFieldName,
@@ -113,18 +112,4 @@ describe("type-utils", () => {
113112
});
114113
});
115114

116-
describe("getSingleNameWithNamespace", () => {
117-
it("replaces dots with underscores", () => {
118-
expect(getSingleNameWithNamespace("My.Namespace.Type")).toBe("My_Namespace_Type");
119-
});
120-
121-
it("trims whitespace", () => {
122-
expect(getSingleNameWithNamespace(" My.Type ")).toBe("My_Type");
123-
});
124-
125-
it("handles names without namespace", () => {
126-
expect(getSingleNameWithNamespace("MyType")).toBe("MyType");
127-
});
128-
});
129-
130115
});

0 commit comments

Comments
 (0)