Add TSP Model -> GraphQLObject type translation#31
Add TSP Model -> GraphQLObject type translation#31FionaBronwen wants to merge 2 commits intofeature/graphqlfrom
Conversation
| /** | ||
| * Map TypeSpec scalar types to GraphQL Built-in types | ||
| */ | ||
| export function mapScalarToGraphQL( |
There was a problem hiding this comment.
Seems like https://github.com/microsoft/typespec/blob/ff28640117f7f58166c9455c4812acd7fc044636/packages/http-client-js/src/components/transforms/scalar-transform.tsx establishes a good pattern to follow here.
Parts of that code (like getScalarTests) should arguably part of a shared library — only the scalarTransformerMap is really emitter-specific. Might want to check with @joheredi on that.
There was a problem hiding this comment.
Yeah I think scalar-transform really belongs in packages/emitter-framework. There is some type-transform in there but I think that is probably not used much and might want to replace with the transforms from http-client-js.
@maorleger - fyi
| // Type maps for different GraphQL types | ||
| #objectTypes: ObjectTypeMap; |
There was a problem hiding this comment.
Do you think we'll want a construct that can return the mapping for any type?
e.g.
#getTypeMap(tspType: Type): TypeMap<Type, Any> {};| * Register a TSP Model | ||
| */ | ||
| addModel(model: Model): void { | ||
| const model_context: TSPContext<Model> = { |
There was a problem hiding this comment.
I think the expected style is to use pascalCase.
Python habits are hard to break 🙂
|
|
||
| const tspEnum = context.tspType as Enum; | ||
| // Create a thunk for the property type that will be resolved later | ||
| const typeThunk = (): GraphQLOutputType | GraphQLInputType => { |
There was a problem hiding this comment.
I think GraphQLOutputType | GraphQLInputType == GraphQLType
| /** | ||
| * Maps a TypeSpec type to a GraphQL type | ||
| */ | ||
| #mapTypeSpecToGraphQL(type: Type): GraphQLOutputType | GraphQLInputType { |
There was a problem hiding this comment.
| enum: (node: Enum) => { | ||
| this.registry.addEnum(node); | ||
| namespace: (namespace: Namespace) => { | ||
| if (namespace.name === "TypeSpec" || namespace.name === "Reflection") { |
There was a problem hiding this comment.
| if (namespace.name === "TypeSpec" || namespace.name === "Reflection") { | |
| if (["TypeSpec", "Reflection"].includes(namespace.name)) { |
| } | ||
|
|
||
| /** | ||
| * TypeMap for GraphQL Object types (output types) |
There was a problem hiding this comment.
Is there some shared functionality here between output object and input object types that warrants a common parent class?
Summary
This PR adds:
GraphQLObjectTypesfrom TSPModelsusing theTypeMapabstract class#privatepropertiesComing Soon in a Followup PR Near You
Models ->GraphQLInputTypes