기본 콘텐츠로 건너뛰기

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 도구를 통해 모델을 가지고 놀아보는 방법을 알아봅시다.

댓글

이 블로그의 인기 게시물

MQTT Broker Mosquitto 설치 후 설정

우분투 기준 $ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa $ sudo apt-get update 하고 $ sudo apt-get install mosquitto 으로 설치하면 서비스까지 착실하게 올라간다. 설치는 간단한데 사용자를 만들어야한다. /etc/mosquitto/mosquitto.conf 파일에서 권한 설정을 변경하자. allow_anonymous false 를 추가해서 아무나 못들어오게 하자. $ service mosquitto restart 서비스를 재시작. 이제 사용자를 추가하자. mosquitto_passwd <암호파일 경로명> <사용자명> 하면 쉽게 만들 수 있다. # mosquitto_passwd /etc/mosquitto/passwd admin Password:  Reenter password:  암호 넣어준다. 두번 넣어준다. 이제 MQTT 약을 열심히 팔아서 Broker 사글세방 임대업을 하자.

cURL로 cookie를 다루는 법

http://stackoverflow.com/questions/22252226/passport-local-strategy-and-curl 레거시 소스를 보다보면 인증 관련해서 cookie를 사용하는 경우가 있는데 가령 REST 서버인 경우 curl -H "Content-Type: application/json" -X POST -d '{"email": "aaa@bbb.com", "pw": "cccc"}' "http://localhost/login" 이렇게 로그인이 성공이 했더라도 curl -H "Content-Type: application/json" -X GET -d '' "http://localhost/accounts/" 이런 식으로 했을 때 쿠키를 사용한다면 당연히 인증 오류가 날 것이다. curl의 --cookie-jar 와 --cookie 옵션을 사용해서 cookie를 저장하고 꺼내쓰자. 각각 옵션 뒤엔 저장하고 꺼내쓸 파일이름을 임의로 지정하면 된다. 위의 과정을 다시 수정해서 적용하면 curl -H --cookie-jar jarfile "Content-Type: application/json" -X POST -d '{"email": "aaa@bbb.com", "pw": "cccc"}' "http://localhost/login" curl -H --cookie jarfile "Content-Type: application/json" -X GET -d '' "http://localhost/accounts/" 이렇게 사용하면

OS X 터미널에서 tmux 사용시 pane 크기 조절

http://superuser.com/a/660072  글 참조. OS X 에서 tmux 사용시 나눠놓은 pane 크기 조정할 때 원래는 ctrl+b, ctrl+↑←→↓ 로 사이즈를 조정하는데 기본 터미널 키 입력이 조금 문제가 있다. 키 매핑을 다시 하자 Preferences(cmd+,) > Profile >  변경하고자 하는 Theme 선택 > Keyboards 로 들어가서 \033[1;5A \033[1;5B \033[1;5C \033[1;5D 를 순서대로 ↑↓→←순으로 매핑이 되도록 하면 된다. +를 누르고 Key에 해당 화살표키와 Modifier에 ctrl 선택 한 후 <esc>, [, 1, ;, 5 까지 한키 한키 입력 후 A,B,C,D를 써준다. 잘못 입력했을 땐 당황하지 말고 Delete on character 버튼을 눌러 수정하도록 하자. 그리고 다시 tmux에서 ctrl+b, ctrl+↑←→↓로 사이즈를 조절해보자. 잘 된다.