quizzical
quizzical copied to clipboard
Expose data model as GraphQL API
E.g. as per https://medium.com/@govorov/creating-graphql-api-with-koa-and-typeorm-8ec0ce2eaadc
Actually, the article above requires recreating all the type definitions manually, which violates DRY. TypeGraphQL only requires decorating existing classes which seems like a much better approach https://github.com/19majkel94/type-graphql
Thanks, I want to experiment with that a bit tomorrow 😄
I added a GraphQL layer to the application. Now npm run start will start a GraphQL server at http://localhost:4000/graphql and a UI at http://localhost:4000/playground. In order to test, I implemented a first field, courses, which returns all courses, and just one field, label. Attached image shows it in action. Now it's matter of augmenting the schema, e.g., implement other types, their fields and mutations. PR at https://github.com/infojunkie/quizzical/pull/8.

I'll work on a lib that auto-generates basic resolvers (list, get by id, create, update and delete) for typeorm entities.
Looks great so far Caio thanks! And yeah an auto-generated CRUD would be :dancer:
There are a few read-only entity methods that already exist, e.g. https://github.com/infojunkie/quizzical/blob/master/src/entity/Enrollment.ts#L44 - we would want to expose these to the client. So it would be good to be able to annotate these methods to become fields in the auto-generated entity type or query.
Another option here found on HN today: https://github.com/acro5piano/typed-graphqlify
Picking up where this left off with TypeGraphQL + Apollo Server