Currently we have TypeORM, which does typing and DB schema but requires you to make a separate API. And we have Prisma, which is a DB schema and API, but still requires you to maintain types.
Currently we have TypeORM, which does typing and DB schema but requires you to make a separate API. And we have Prisma, which is a DB schema and API, but still requires you to maintain types.
If that's not a concern, and you want speed/ease of development, take a look at TypeGraphQL [1]. They have a couple of examples [2][3] of how nicely it plays with TypeORM. You can create one set of domain object classes, annotate them with decorators for both TypeGraphQL and TypeORM, and then expose a GraphQL schema that matches the underlying database with a minimal amount of code (you could probably even get clever with some generic fucntions to cut down the code you'd need to write for the resolvers).
[1] https://typegraphql.com/ [2] https://github.com/MichalLytek/type-graphql/tree/v0.17.5/exa... [3] https://github.com/MichalLytek/type-graphql/tree/v0.17.5/exa...
True.
Would be nice to have some kind of graphical tool, that would allow to model these things.
Add databases
Extract the schemas from these databases automatically, which should be trivial with SQL databases
Create GraphQL types manually
link the types up with the databases (the tricky part, especially with multiple different databases)
the API is literally a query language for the DB
No, SQL is literally a query language for the DB.The API is the contract you define for how people with interact with your application. While some people may choose to model this after their underlying database, conceptually, they are very different.
On small applications, maybe you can get away with treating them as one and the same, but for longer-lived applications which need to integrate and co-exist with other systems/services, that choice can come back to bite you.
I'm not saying you shouldn't/can't treat them as the same thing, just be sure you know the trade-offs and long-term repercussions.
I am currently playing around with it and although it has some rough edges in corner cases, for 99% of my use cases it was a breeze to work with. Particulary the integration with nexus via the nexus-prisma plugin [2] is plain awesome, i have never had a fully functional graphql endpoint standing in a timeframe of 1 hour.
I am using it in conjunction with NextJS and the resulting developer experience is great, i cant recommend enough to try it out
(I am not affiliated with prisma labs, just a happy user)
[0] https://github.com/prisma/prisma2
[1] https://www.notion.so/Is-Prisma-2-Ready-8b3fba3eaf5b4bf3ab71...
For people who want to learn more about using Prisma together with Nexus (which enables exposing DB models via GraphQL), I also recommend checking the next iteration of Nexus that we're currently working on (which will turn into a fully-fledged GraphQL application framework with TypeScript as a first-class citizen): https://nexus-future.now.sh/#/
Let me know if you have any questions!
[0] - https://medium.com/open-graphql/automatically-generate-types...
Also, the Relay compiler will emit Flow types in its compiled fragments by default, and can be configured to emit TypeScript types instead (AFAIK, you can't generate both types simultaneously).
DB side is not handled by the tool because that's a blackbox the client don't need to know.