Skip to content

Commit 11b0f8d

Browse files
committed
Fix review findings: document implements clause behavior, remove unused imports
- Add explanatory comment on getComposition/iface.name in object-type.tsx clarifying that pre-mutation names match post-mutation names (mutation engine doesn't rename models) - Remove unused `type Model` import from all G2 test files
1 parent 4b8cc81 commit 11b0f8d

6 files changed

Lines changed: 13 additions & 13 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Model, getDoc } from "@typespec/compiler";
1+
import type { Model } from "@typespec/compiler";
22
import * as gql from "@alloy-js/graphql";
33
import { useTsp } from "@typespec/emitter-framework";
44
import { useGraphQLSchema } from "../../context/index.js";
@@ -17,9 +17,9 @@ export interface InputTypeProps {
1717
* - Otherwise, uses the name as-is
1818
*/
1919
export function InputType(props: InputTypeProps) {
20-
const { program } = useTsp();
20+
const { $ } = useTsp();
2121
const { modelVariants } = useGraphQLSchema();
22-
const doc = getDoc(program, props.type);
22+
const doc = $.type.getDoc(props.type);
2323
const properties = Array.from(props.type.properties.values());
2424

2525
// If there's an output variant with the same name, add Input suffix

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Model, getDoc } from "@typespec/compiler";
1+
import type { Model } from "@typespec/compiler";
22
import * as gql from "@alloy-js/graphql";
33
import { useTsp } from "@typespec/emitter-framework";
44
import { Field } from "../fields/index.js";
@@ -14,8 +14,8 @@ export interface InterfaceTypeProps {
1414
* Interfaces are marked with @Interface decorator in TypeSpec
1515
*/
1616
export function InterfaceType(props: InterfaceTypeProps) {
17-
const { program } = useTsp();
18-
const doc = getDoc(program, props.type);
17+
const { $ } = useTsp();
18+
const doc = $.type.getDoc(props.type);
1919
const properties = Array.from(props.type.properties.values());
2020

2121
return (

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Model, getDoc } from "@typespec/compiler";
1+
import type { Model } from "@typespec/compiler";
22
import * as gql from "@alloy-js/graphql";
33
import { useTsp } from "@typespec/emitter-framework";
44
import { Field, OperationField } from "../fields/index.js";
@@ -19,13 +19,16 @@ export interface ObjectTypeProps {
1919
* - Operation fields via @operationFields
2020
*/
2121
export function ObjectType(props: ObjectTypeProps) {
22-
const { program } = useTsp();
23-
const doc = getDoc(program, props.type);
22+
const { $, program } = useTsp();
23+
const doc = $.type.getDoc(props.type);
2424
const properties = Array.from(props.type.properties.values());
2525
const implementations = getComposition(program, props.type);
2626
const operationFields = getOperationFields(program, props.type);
2727

28-
// Convert interface implementations to string references
28+
// Convert interface implementations to string references.
29+
// Note: getComposition returns original (pre-mutation) models from decorator state.
30+
// This works because the mutation engine doesn't rename models, so iface.name
31+
// matches the name used by InterfaceType for the same model.
2932
const implementsRefs = implementations?.map((iface) => iface.name) || [];
3033

3134
return (

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type Model } from "@typespec/compiler";
21
import { t } from "@typespec/compiler/testing";
32
import { describe, expect, it, beforeEach } from "vitest";
43
import { InputType } from "../../src/components/types/index.js";

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type Model } from "@typespec/compiler";
21
import { t } from "@typespec/compiler/testing";
32
import { describe, expect, it, beforeEach } from "vitest";
43
import { InterfaceType } from "../../src/components/types/index.js";

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type Model } from "@typespec/compiler";
21
import { t } from "@typespec/compiler/testing";
32
import * as gql from "@alloy-js/graphql";
43
import { describe, expect, it, beforeEach } from "vitest";

0 commit comments

Comments
 (0)