Skip to content

Commit 671900f

Browse files
committed
Remove modelVariants workaround from components
The mutation engine now handles all input/output type naming, so components can use type.name directly without looking up whether a model has both input and output variants.
1 parent 77ba309 commit 671900f

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

packages/graphql/src/components/types/input-type.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Model } from "@typespec/compiler";
22
import * as gql from "@alloy-js/graphql";
33
import { useTsp } from "@typespec/emitter-framework";
4-
import { useGraphQLSchema } from "../../context/index.js";
54
import { Field } from "../fields/index.js";
65

76
export interface InputTypeProps {
@@ -12,22 +11,16 @@ export interface InputTypeProps {
1211
/**
1312
* Renders a GraphQL input type declaration
1413
*
15-
* Determines the correct input type name:
16-
* - If the model is also an output type, appends "Input"
17-
* - Otherwise, uses the name as-is
14+
* The mutation engine handles naming: input models are already suffixed
15+
* with "Input" when they need to be distinguished from output types.
1816
*/
1917
export function InputType(props: InputTypeProps) {
2018
const { $ } = useTsp();
21-
const { modelVariants } = useGraphQLSchema();
2219
const doc = $.type.getDoc(props.type);
2320
const properties = Array.from(props.type.properties.values());
2421

25-
// If there's an output variant with the same name, add Input suffix
26-
const hasOutputVariant = modelVariants.outputModels.has(props.type.name);
27-
const inputTypeName = hasOutputVariant ? `${props.type.name}Input` : props.type.name;
28-
2922
return (
30-
<gql.InputObjectType name={inputTypeName} description={doc}>
23+
<gql.InputObjectType name={props.type.name} description={doc}>
3124
{properties.map((prop) => (
3225
<Field property={prop} isInput={true} />
3326
))}

packages/graphql/test/components/input-type.test.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,21 @@ describe("InputType component", () => {
4949
expect(sdl).toContain("bio: String!");
5050
});
5151

52-
it("appends Input suffix when model has an output variant", async () => {
53-
const { Pet } = await tester.compile(
54-
t.code`model ${t.model("Pet")} { name: string; }`,
52+
it("renders mutated input model with Input suffix from mutation engine", async () => {
53+
// The mutation engine adds the Input suffix when a model is used as input.
54+
// This test simulates that by using a model already named with Input suffix.
55+
const { PetInput } = await tester.compile(
56+
t.code`model ${t.model("PetInput")} { name: string; }`,
5557
);
5658

57-
const sdl = renderComponentToSDL(tester.program, <InputType type={Pet} />, {
58-
modelVariants: {
59-
outputModels: new Map([["Pet", Pet]]),
60-
inputModels: new Map([["Pet", Pet]]),
61-
},
62-
});
59+
const sdl = renderComponentToSDL(tester.program, <InputType type={PetInput} />);
6360

6461
expect(sdl).toContain("input PetInput {");
6562
});
6663

67-
it("uses original name when no output variant exists", async () => {
64+
it("renders input-only model without suffix", async () => {
65+
// Models used only as inputs (never as outputs) don't need the Input suffix.
66+
// The mutation engine handles this - it only adds suffix when needed.
6867
const { CreatePet } = await tester.compile(
6968
t.code`model ${t.model("CreatePet")} { name: string; }`,
7069
);

0 commit comments

Comments
 (0)