4 ms·
Im right now building my backend on GraphQL and TypeScript. Great DX. GraphQL Modules + TypeGraphQL, Apollo Server, TypeORM (pg for prod and sqlite3 for dev/t
by agustif 6y ago
Im right now building my backend on GraphQL and TypeScript.
Great DX.
GraphQL Modules + TypeGraphQL, Apollo Server, TypeORM (pg for prod and sqlite3 for dev/test)
Works pretty nicely auto-generating both graphql fields/querys/mutations/schema and entities/models from database from a single source of turth. I made a template from type-graphql's graphql-modules example to work as a separate codebase, if someone is interested I could switch it from private to public and share the link here
- rattray 6y agoWow, I hadn't seen before how you can mix model and gql code with TypeORM and TypeGraphQL before. Looks really convenient, especially with an auto-generator. Have you ran into footguns? Did you try postgraphile? Any thoughts? Curious to see how you string it all together...
- agustif 6y agoHey haven't tried postgraphile, but have tried Prisma/Hasura which seem to be on the same SaaS-GraphQL space. They're all valid products, but my stack is 100% fully open source, and there's no PRO to buy for any of the options. I based it off the creator of TypeGraphQL GQL-Modules+TypeGraphQL v1 example: https://github.com/MichalLytek/type-graphql/tree/master/examples/graphql-modules https://github.com/MichalLytek/type-graphql/tree/master/exam... And a LogRocket's blogpost about TypeORM+TypeGraphQL: https://blog.logrocket.com/how-build-graphql-api-typegraphql-typeorm/ https://blog.logrocket.com/how-build-graphql-api-typegraphql... I need to add typeorm/models to my template before sharing, but as an example here's a model which is also a type, using both @ObjectType() & @Field() (type-graphql and @BaseEntity() & @Column() (typeorm)class decorators. ```user.model.ts import { Field, ID, Int, ObjectType, } from 'type-graphql'; import { BaseEntity, Column, Entity, PrimaryGeneratedColumn, } from 'typeorm'; @Entity() @ObjectType() export default class User extends BaseEntity { @Field(() => ID) @PrimaryGeneratedColumn() id?: typeof ID; @Field() @Column() name: string; @Field() @Column() email: string; @Field(type => Int) @Column() age: number; } ``` and this is what type-graphql auto-generates for a user schema. ```user.schema.ts # !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!! # !!! DO NOT MODIFY THIS FILE BY YOURSELF !!! type Document { author: User! authorId: ID! } type Notification { author: User! authorId: ID! } type Query { users: [User!]! } type User { age: Int! email: String! id: ID! name: String! } ```
- rattray 6y agoNice, thanks! Fwiw, postgraphile is open source and can be plugged into any express app. But I don't think it provides an orm layer or equivalent, so I can see the advantage of this approach too!
- agustif 6y agoSorry, my bad, I briefly checked their homepage and saw a pro button somewhere: https://www.graphile.org/postgraphile/pricing/ https://www.graphile.org/postgraphile/pricing/ Although it's a totally acceptable monetization strategy for any OSS to offer cloud+enterprise support, for my personal projects at least I prefer to choose projects which are more personal/community driven than commercial to put it simply. But yeah I basically like TypeORM generally also gonna use typeorm-seeding on the mix to stress test the app.
- BenjieGillam 6y ago<checks the income from the pro plugin versus that from sponsorship> I can definitely confirm that we're significantly more personal/community driven than commercial.
- MH15 6y agoI'm interested please share!