-
Notifications
You must be signed in to change notification settings - Fork 0
Add TSP Model -> GraphQLObject type translation #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/graphql
Are you sure you want to change the base?
Conversation
/** | ||
* Map TypeSpec scalar types to GraphQL Built-in types | ||
*/ | ||
export function mapScalarToGraphQL( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum: (node: Enum) => { | ||
this.registry.addEnum(node); | ||
namespace: (namespace: Namespace) => { | ||
if (namespace.name === "TypeSpec" || namespace.name === "Reflection") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (namespace.name === "TypeSpec" || namespace.name === "Reflection") { | |
if (["TypeSpec", "Reflection"].includes(namespace.name)) { |
@@ -101,3 +159,143 @@ export abstract class TypeMap<T extends Type, G extends GraphQLType> { | |||
*/ | |||
protected abstract materialize(context: TSPContext<T>): G; | |||
} | |||
|
|||
/** | |||
* TypeMap for GraphQL Object types (output types) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some shared functionality here between output object and input object types that warrants a common parent class?
Summary
This PR adds:
GraphQLObjectTypes
from TSPModels
using theTypeMap
abstract class#private
propertiesComing Soon in a Followup PR Near You
Model
s ->GraphQLInputType
s