Skip to content

Commit 50cd3e4

Browse files
committed
Add operation to main.tsp for testing
1 parent d8d9eeb commit 50cd3e4

4 files changed

Lines changed: 10 additions & 28152 deletions

File tree

packages/graphql/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
"peerDependencies": {
5959
"@typespec/compiler": "workspace:~",
6060
"@typespec/emitter-framework": "^0.5.0",
61-
"@typespec/http": "workspace:~"
61+
"@typespec/http": "workspace:~",
62+
"@typespec/mutator-framework": "workspace:~"
6263
},
6364
"devDependencies": {
6465
"@types/node": "~22.13.13",
65-
"@typespec/mutator-framework": "workspace:~",
6666
"rimraf": "~6.0.1",
6767
"source-map-support": "~0.5.21",
6868
"typescript": "~5.8.2",

packages/graphql/src/registry.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,28 @@ import {
99
} from "graphql";
1010
import { type TypeKey } from "./type-maps.js";
1111
import { 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
*/
3235
export 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",

packages/graphql/test/main.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ namespace MyLibrary {
2525
Fantasy,
2626
}
2727

28+
op getBooks(): Book[];
2829
op createBook(book: Book): Book;
2930
}

0 commit comments

Comments
 (0)