-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
expose graphql schema via factory.toSchema
#96
Conversation
src/factory.ts
Outdated
if (type === 'graphql') { | ||
return generateGraphQLHandlers(modelName, definition, api, baseUrl) | ||
} | ||
|
||
return generateRestHandlers(modelName, definition, api, baseUrl) | ||
}, | ||
toSchema(type: 'graphql') { |
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.
Given we support only GraphQL schema, what do you think about naming this method .toGraphQLSchema()
instead? Once we support more types, if ever, we can move to a more generic .toSchema
.
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.
Sure! I was assuming this would be the "least breaking" upgrade path in case you introduce stuff like OpenAPI schemas in the future, but I see why it could be confusing for users that discover the API without TypeScript.
I'll change it.
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.
Renamed it as requested :)
/** | ||
* Generate request handlers of the given type based on the model. | ||
*/ | ||
toHandlers(type: 'graphql', baseUrl?: string): GraphQLHandler[] |
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.
Thank you for these overloads, this is great! ✨
Hey, @phryneas. Thank you for these improvements, I think they're great. I've only had one concern about the |
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.
This is great. Thank you for your work on this and welcome to contributors! 🎉
This allows to expose the schema directly, to be consumed for example by graphql-codegen - and in consequence by TypeScript (via generated types) or the Apollo Graphql VSCode extension (via an exported introspection schema)
As an example: