Skip to content

Files

Latest commit

 

History

History
114 lines (73 loc) · 1.14 KB

deck.mdx

File metadata and controls

114 lines (73 loc) · 1.14 KB

import { future, highlight } from '@mdx-deck/themes'

export const theme = { ...future, ...highlight }

@linstobias

Tobias Lins

  • Freelance Consultant - React & NodeJS
  • Building splitbee.io

Type safety between Database and Frontend


Where do you need types?

Relational Database

Typescript server-side

GraphQL Schema

Typescript client


Possible Solution

  • typeorm
  • typegraphql
  • graphql-code-generator

typeorm

@Entity()
export class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    firstName: string;
}

typeorm.io


TypeGraphQL

@ObjectType()
export class User {
    @Field()
    id: number;

    @Field()
    firstName: string;
}

typegraphql.com


graphql-code-generator

schema: http://localhost:3000/graphql
generates:
  ./src/types.d.ts:
    plugins:
      - typescript

graphql-code-generator.com


Live Coding Example


Summary

  • Define type on server
  • Typescript class as backend typing
  • Generated type on client
  • Type safe access

Questions