quizzical icon indicating copy to clipboard operation
quizzical copied to clipboard

Expose data model as GraphQL API

Open infojunkie opened this issue 7 years ago • 7 comments

E.g. as per https://medium.com/@govorov/creating-graphql-api-with-koa-and-typeorm-8ec0ce2eaadc

infojunkie avatar Oct 06 '18 20:10 infojunkie

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

infojunkie avatar Oct 13 '18 23:10 infojunkie

Thanks, I want to experiment with that a bit tomorrow 😄

caiosba avatar Oct 13 '18 23:10 caiosba

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. graphql

caiosba avatar Oct 15 '18 15:10 caiosba

I'll work on a lib that auto-generates basic resolvers (list, get by id, create, update and delete) for typeorm entities.

caiosba avatar Oct 15 '18 16:10 caiosba

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.

infojunkie avatar Oct 15 '18 16:10 infojunkie

Another option here found on HN today: https://github.com/acro5piano/typed-graphqlify

infojunkie avatar Dec 26 '18 15:12 infojunkie

Picking up where this left off with TypeGraphQL + Apollo Server

infojunkie avatar Sep 11 '20 06:09 infojunkie