기본 콘텐츠로 건너뛰기

vulcanJS - 4. 글쓰기를 위한 graphQL 모델 만들기

조금 어려울지도 모릅니다.
이제까지 쉽게쉽게 왔습니다만 여기서부터 갑자기 이것저것 많이 나옵니다.
그러니 너무 상심하지말고 차분하게 따라가봅시다.

신나는 백엔드의 세계에 오신 걸 환영합니다 :)
글쓰기를 구현하기 위해 Posts라는 모델을 만들어봅시다.
여담이지만 N개의 목록으로 구성하는 것들을 Collection이라고 하는데 보통 복수형인 s를 뒤에 붙여서 만드는 것이 일반적입니다. 첫글자를 대문자로 시작하는 Camel Notation도 사용합니다.
$ vulcan g model
하고 쳐봅니다.
패키지 이름 선택하고 나서 Model name을 입력합니다. resolvers와 mutations는 디폴트 No로 엔터엔터하시고나면 ? Add a custom property to the collection (y/N) 라고 나옵니다.
$ vulcan g model
? Package name spectrum-simplebb
? Model name Posts
? Add custom resolvers No
? Add custom mutations No
? Add a custom property to the collection (y/N)
소스를 수정해서 해도 되지만 우리는 아무것도 아는게 없으니 custom property를 줘서 만들어봅시다.
글쓰기에서 중요한 게 무엇일까요?
잘 생각이 나진 않지만 최소 "제목", "본문글" 정도는 있어야겠다는 생각이 듭니다.
일단 y 하고 title, body를 각각 String 타입으로 생성해봅시다.
? Add a custom property to the collection Yes
? Property name title
? Property is hidden No
? Property label Title
? Property type String
? Property is optional No
? Property viewable by Guests
? Property insertable by Members
? Property editable by Members
? Add another custom property to the collection Yes
쭉 넣어봅니다.
hidden은 No. 노출이 되야죠.
label은 Title 이라고 대문자로 써줍시다. 나중에 SmartForms가 사용합니다.
type은 문자열이니 String이고 Optional은 필수 여부인데 제목은 꼭 들어가도록 하기 위해 No
viewable/insertable/editable이 조금 신기합니다.
볼 수 있는, 추가할 수 있는 , 수정할 수 있는 권한을 Guest/Members/Admin 으로 나누어서 지정할 수 있습니다.
보는 건 Guests도 가능하게 쓰고 수정하는 건 Members만 가능하게 해봅시다.
그리고 더 custom property를 넣을거냐고 묻는데 Yes(Y) 해줍시다.
body도 동일하게 하되 optional을 Yes로 해서 제곧내(제목이 곧 내용) 처리를 할 수 있게 합시다.
전체적으로 보면 이렇게 보일 것입니다.
$ vulcan g model
? Package name spectrum-simplebb
? Model name Posts
? Add custom resolvers No
? Add custom mutations No
? Add a custom property to the collection Yes
? Property name title
? Property is hidden No
? Property label Title
? Property type String
? Property is optional No
? Property viewable by Guests
? Property insertable by Members
? Property editable by Members
? Add another custom property to the collection Yes
? Property name body
? Property is hidden No
? Property label Body
? Property type String
? Property is optional Yes
? Property viewable by Guests
? Property insertable by Members
? Property editable by Members
? Add another custom property to the collection No
   create packages/spectrum-simplebb/lib/modules/posts/collection.js
 conflict packages/spectrum-simplebb/lib/modules/index.js
? Overwrite packages/spectrum-simplebb/lib/modules/index.js? overwrite
    force packages/spectrum-simplebb/lib/modules/index.js
   create packages/spectrum-simplebb/lib/modules/posts/fragments.js
   create packages/spectrum-simplebb/lib/modules/posts/schema.js
   create packages/spectrum-simplebb/lib/modules/posts/permissions.js
   create packages/spectrum-simplebb/lib/modules/posts/parameters.js
modules라는 폴더에 이것저것 생성하는 것을 볼 수 있습니다.
이걸로 준비는 다 되었습니다.
모델을 구현한 것과 그걸 화면에서 보는 것은 또 다른 문제입니다.
하지만 다행히도 우리는 graphQL을 쓰고 있고
graphQL에선 조회(Query)와 변화(Mutation)를 시험해볼 수 있는 도구를 제공합니다.
다음엔 graphQL 도구를 통해 모델을 가지고 놀아보는 방법을 알아봅시다.

댓글

이 블로그의 인기 게시물

세상 간단한 https(+secured websocket): Caddy

nginx, apache2 같은 걸로 매번 certbot 연동을 통해 https 하는게 지겨워서 알아보니 Caddy라는게 있더라. 설치법은 강하게 크기 위해 알아서 해본다. # cat /etc/caddy/Caddyfile your.shitty.site:8123 {   proxy / localhost:9123 {     websocket     transparent   } } 이건 외부에서 8123으로 들어오는 걸 내부적으로 9123로 맞춰서 https 맞춰주는 reverse proxy. 만일 port를 생략하면 # cat /etc/caddy/Caddyfile your.shitty.site {   proxy / localhost:9123 {     websocket     transparent   } } 기본포트인 443으로 되어 https://your.shitty.site 로 접속이 된다. 요새 말썽이던 cloudflare 버리고 netlify domain이랑 caddy를 쓰니까 앓던 이가 빠진 느낌. 이 조합은 당분간 계속 써야겠다 싶다.

저지연 오디오 생성 LLVC 사용기

https://github.com/KoeAI/LLVC 써봄 CUDA 11.8 버전 쓰고 있어 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 VC 없어서 설치 https://wikidocs.net/168848 참조 FAIRSEQ 관련 오류 https://github.com/facebookresearch/fairseq/issues/2908 pip install editdistance  설치 No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8' 오류 멀쩡하게 있는데 안됨. pip install torch==2.1.0+cu118 torchvision==0.16.0+cu118 torchaudio==2.1.0+cu118 --extra-index-url https://download.pytorch.org/whl/cu118 다시 설치 set DISTUTILS_USE_SDK=1 이게 문젠가 설정하고 재도전 Using cached ruamel.yaml.clib-0.2.8-cp311-cp311-win_amd64.whl (118 kB) Building wheels for collected packages: fairseq   Building wheel for fairseq (pyproject.toml) ... error   error: subprocess-exited-with-error   × Building wheel for fairseq (pyproject.toml) did not run successfully.   │ exit code: 1   ╰─> [1829 lines of output]       No CUDA runtime is found, usi...