You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#29 was getting too large 👀 , so I've started the process of breaking it up into more easily digested pieces. This PR adds a new TypeMap abstract class to be used in the GraphQLTypeRegistry.
Note: This PR does not yet add the abstract class's implementations (i.e. ModelTypeMap, EnumTypeMap, etc.).
TypeMap<T, G> Base Class
Purpose
Generic base class that provides the core registration and materialization lifecycle for mapping TypeSpec types (T) to GraphQL types (G).
Key Properties
registrationMap: Storage for TypeSpec contexts awaiting materialization materializedMap: Cache of already-created GraphQL types
Core Methods
register(context: TSPContext<T>): string
Stores TypeSpec type with metadata for later materialization
Performs conflict detection for duplicate registrations
Returns the registration name used as a key
get(name: string): G | undefined
Returns cached GraphQL type if already materialized
Attempts lazy materialization if type is registered but not yet materialized
Caches result for future calls
Utility Methods
isRegistered(name: string): Check if a type is registered getAllMaterialized(): G[]: Get all cached GraphQL types reset(): Clear all registrations and cache
Abstract Methods (Subclass Responsibility)
getNameFromContext(context): Extract registration name from context materialize(context): Create the actual GraphQL type from TypeSpec context
One thing discussed in the other PR is that we want to avoid collisions in the materialized types. If we have separate TypeMaps for different TSP types (ModelMap, EnumMap, ScalarMap, et al), where do we catch collisions among the different maps — e.g. we have a model, a scalar, and an enum all named Foo?
One thing discussed in the other PR is that we want to avoid collisions in the materialized types. If we have separate TypeMaps for different TSP types (ModelMap, EnumMap, ScalarMap, et al), where do we catch collisions among the different maps — e.g. we have a model, a scalar, and an enum all named Foo?
I'm thinking we could keep some global state within the registry itself to track names for name collisions and then we would consult that set to check for a collision before adding new entries in each TypeMap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#29 was getting too large 👀 , so I've started the process of breaking it up into more easily digested pieces. This PR adds a new
TypeMapabstract class to be used in theGraphQLTypeRegistry.Note: This PR does not yet add the abstract class's implementations (i.e.
ModelTypeMap,EnumTypeMap, etc.).TypeMap<T, G>Base ClassPurpose
Generic base class that provides the core registration and materialization lifecycle for mapping TypeSpec types (
T) to GraphQL types (G).Key Properties
registrationMap: Storage for TypeSpec contexts awaiting materializationmaterializedMap: Cache of already-created GraphQL typesCore Methods
register(context: TSPContext<T>): stringget(name: string): G | undefinedUtility Methods
isRegistered(name: string): Check if a type is registeredgetAllMaterialized(): G[]: Get all cached GraphQL typesreset(): Clear all registrations and cacheAbstract Methods (Subclass Responsibility)
getNameFromContext(context): Extract registration name from contextmaterialize(context): Create the actual GraphQL type from TypeSpec context