# 1. 프리즈마 데이터 모델을 작성해 봅시다.
- 새로운 타입 정의 하기. User라고 정의하면
type User{이안에 데이터 필드를 채우면 됩니다.}
# 2 . 1개의 데이터 타입은 prisma가 자동으로 쿼리랑 뮤테이션을 만들어 줍니다.
한마디로, 나는 User객체만 만들었는데, 자동으로 CURD 관련 기능을 만들어 줍니다.!
- 쿼리 users, user, usersConnection
- 뮤테이션 createUser, updateUser , deleteUser, upsertUser,
- 뮤테이션 updateManyUsers, deleteManyUsers
## 2. 데이터 요소 정의하기
## 2.0 id 정의하기
type User {
id: ID! @id
...
}
## 2.1 String으로 필드 만들기 + 생성 및 업데이트 기록하기
id: ID! @id
name: String! @unique
name: String!
name: String
name: String! @default(value: "")
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
## 2.2 데이터 relation
posts: [Post!]! @relation(name: "PostsOfUser", onDelete: CASCADE)
user: User @relation(name: "PostsOfUser")
## 2.2 데이터 relation 같은 타입내
following: [User!]! @relation(name: "FollowRelation")
followers: [User!]! @relation(name: "FollowRelation")
# 3. 예제 인스타그램 클론의 데이터모델
type User {
id: ID! @id
avatar: String
name: String! @unique
email: String! @unique
firstName: String @default(value: "")
lastName: String
bio: String
following: [User!]! @relation(name: "FollowRelation")
followers: [User!]! @relation(name: "FollowRelation")
posts: [Post!]! @relation(name: "PostsOfUser", onDelete: CASCADE)
likes: [Like!]! @relation(name: "LikesOfUser", onDelete: CASCADE)
comments: [Comment!]! @relation(name: "CommentsOfUser", onDelete: CASCADE)
rooms: [Room!]!
loginSecret: String
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Post {
id: ID! @id
location: String
caption: String!
user: User @relation(name: "PostsOfUser")
files: [File!]! @relation(name: "FilesOfPost", onDelete: CASCADE)
likes: [Like!]! @relation(name: "LikeOfPost", onDelete: CASCADE)
comments: [Comment!]! @relation(name: "CommentOfPost", onDelete: CASCADE)
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Like {
id: ID! @id
user: User @relation(name: "LikesOfUser")
post: Post @relation(name: "LikeOfPost")
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Comment {
id: ID! @id
text: String!
user: User @relation(name: "CommentsOfUser")
post: Post @relation(name: "CommentOfPost")
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type File {
id: ID! @id
url: String!
post: Post @relation(name: "FilesOfPost")
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Room {
id: ID! @id
participants: [User!]!
messages: [Message!]!
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Message {
id: ID! @id
text: String!
from: User! @relation(name: "From")
to: User! @relation(name: "To")
room: Room!
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
DOS IMPACT - WEB Developer
KIM DO YOUNG
WEB : REACT JS | REACT NATIVE | GraphQL PRISMA
'GraphQL BackEnd > Lecture' 카테고리의 다른 글
GraphQL + Prisma (5) Prisma Connection파트 (0) | 2020.02.07 |
---|---|
GraphQL + Prisma (4) Prisma fragment 파트 (0) | 2020.02.07 |
GraphQL + Prisma (2) Prisma 쿼리파트 (0) | 2020.02.07 |
GraphQL + Prisma 환경설정 (0) | 2020.02.03 |
백단 환경 구축하기 - GraphQL + Prisma (0) | 2020.02.01 |