@@ -9,25 +9,28 @@ import {
99} from "graphql" ;
1010import { type TypeKey } from "./type-maps.js" ;
1111import { EnumTypeMap , ModelTypeMap } from "./type-maps/index.js" ;
12-
1312/**
1413 * GraphQLTypeRegistry manages the registration and materialization of TypeSpec (TSP)
1514 * types into their corresponding GraphQL type definitions.
1615 *
1716 * The registry operates in a two-stage process:
1817 * 1. Registration: TSP types (like Enums, Models, etc.) are first registered
1918 * along with relevant metadata (e.g., name, usage flags). This stores an
20- * intermediate representation without immediately creating GraphQL types.
19+ * intermediate representation (`TSPTypeContext`) without immediately creating
20+ * GraphQL types. This stage is typically performed while traversing the TSP AST.
21+ * Register type by calling the appropriate method (e.g., `addEnum`).
2122 *
2223 * 2. Materialization: When a GraphQL type is needed (e.g., to build the final
23- * schema or resolve a field type), the registry materializes the TSP type
24+ * schema or resolve a field type), the registry can materialize the TSP type
2425 * into its GraphQL counterpart (e.g., `GraphQLEnumType`, `GraphQLObjectType`).
26+ * Materialize types by calling the appropriate method (e.g., `materializeEnum`).
2527 *
2628 * This approach helps in:
2729 * - Decoupling TSP AST traversal from GraphQL object instantiation.
2830 * - Caching materialized GraphQL types to avoid redundant work and ensure object identity.
2931 * - Handling forward references and circular dependencies, as types can be
30- * registered first and materialized later when all dependencies are known.
32+ * registered first and materialized later when all dependencies are known or
33+ * by using thunks for fields/arguments.
3134 */
3235export class GraphQLTypeRegistry {
3336 // TypeMaps for each type kind
@@ -37,9 +40,6 @@ export class GraphQLTypeRegistry {
3740 // Track all registered names to detect cross-TypeMap name collisions
3841 private allRegisteredNames = new Set < string > ( ) ;
3942
40- /**
41- * Register a TypeSpec Enum for later materialization.
42- */
4343 addEnum ( tspEnum : Enum ) : void {
4444 const enumName = tspEnum . name ;
4545
@@ -81,9 +81,6 @@ export class GraphQLTypeRegistry {
8181 return this . modelTypeMap . get ( modelName as TypeKey ) ;
8282 }
8383
84- /**
85- * Build the final GraphQL schema configuration.
86- */
8784 materializeSchemaConfig ( ) : GraphQLSchemaConfig {
8885 // Collect all materialized types from all TypeMaps
8986 const allMaterializedGqlTypes : GraphQLNamedType [ ] = [
@@ -92,7 +89,6 @@ export class GraphQLTypeRegistry {
9289 ] ;
9390 // TODO: Query type will come from operations
9491 let queryType : GraphQLObjectType | undefined = undefined ;
95-
9692 if ( ! queryType ) {
9793 queryType = new GraphQLObjectType ( {
9894 name : "Query" ,
0 commit comments