https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-nestjs/src 분석

도토리의수난·2021년 2월 1일
0

post.ts 이다

import 'reflect-metadata'
import { ObjectType, Field, ID } from '@nestjs/graphql'
import { User } from './user'

@ObjectType()
export class Post {
  @Field((type) => ID)
  id: number

  @Field()
  title: string

  @Field((type) => String, { nullable: true })
  content: string | null

  @Field((type) => Boolean, { nullable: true })
  published?: boolean | null

  @Field((type) => User, { nullable: true })
  author?: User | null
}

schema.gql이다

type User {
  id: ID!
  email: String!
  name: String
  posts: [Post!]
}

type Post {
  id: ID!
  title: String!
  content: String
  published: Boolean
  author: User
}

type Query {
  post(where: PostIDInput!): Post
  filterPosts(searchString: String!): [Post!]!
  feed: [Post!]!
  user(id: Float!): User
}

input PostIDInput {
  id: Int!
}

type Mutation {
  createDraft(authorEmail: String!, content: String, title: String!): Post!
  publish(id: Float!): Post
  deleteOnePost(where: PostIDInput!): Post
  signupUser(data: SignupUserInput!): User!
}

input SignupUserInput {
  name: String
  email: String!
}

schema.prisma이다

generator client {
  provider        = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

model User {
  email String  @unique
  id    Int     @id @default(autoincrement())
  name  String?
  posts Post[]
}

model Post {
  authorId  Int?
  content   String?
  id        Int     @id @default(autoincrement())
  published Boolean @default(false)
  title     String
  author    User?   @relation(fields: [authorId], references: [id])
}

그러니까 prisma는 database를 그대로 갖는다 -> schema.prisma
post.ts는 nestjs-graphql에서 만든것이다
뇌피셜로 일단은 테이블에 대한 정보를 알아야지 table에서 모든 내용을 다 불러오는 것과
다른이야기다
프리즈마는 서비스만 주입하고 안쓰인다
테이블 추가시에
-schema.prisma table 추가 (이것도 테이블에 종속된다 )
db.migration
entity ts file 생성 (이것도 테이블에 종속된다)
schema.gql 설정 및 기록 (이것도 테이블에 종속된다)
resolver 구현 및 기록
이런 개짓거리를 해야한다
그런데 이렇게 하면 내가보기엔 타입이 확실히 지정이 되서 유지보수가 가능해지는듯 하다
자바 인텔리제이에 종속되면 왠지 피볼 수 도 있으니까

profile
도가도비상도

0개의 댓글