๐ Gato GraphQL v0.7 ์ถ์ โ mutation ๋ฐ nested mutation ์ง์ ์ถ๊ฐ!
Gato GraphQL ๋ฒ์ 0.7์ด ์ถ์๋์์ต๋๋ค. mutation๊ณผ nested mutation์ ์ง์ํฉ๋๋ค! ๐

์๋กญ๊ฒ ์ถ๊ฐ๋ ๊ธฐ๋ฅ๋ค์ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
1. Mutations! ๐
GraphQL mutations๋ ์ฟผ๋ฆฌ๋ฅผ ํตํด ๋ฐ์ดํฐ๋ฅผ ์์ (์ฆ, ๋ถ์์ฉ์ ์คํ)ํ ์ ์๊ฒ ํด์ค๋๋ค.
Mutation์ Gato GraphQL์ ์์ง ์์๋ ์ค์ํ ๊ธฐ๋ฅ์ด์์ต๋๋ค. ์ด์ ์ถ๊ฐ๋์์ผ๋ฏ๋ก, ์ด GraphQL ์๋ฒ๋ ๊ฑฐ์ ๊ธฐ๋ฅ์ด ์์ ํ๋ค๊ณ ํ ์ ์์ต๋๋ค(subscriptions๋ง ๋จ์ ์์ผ๋ฉฐ, ์ถ๊ฐ ๋ฐฉ๋ฒ์ ๋ํด ์ด๋ฏธ ๊ฒํ ์ค์ ๋๋ค).

๋๊ธ ์ถ๊ฐ ์์๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค. ๋ค๋ง, ๋จผ์ ๋ก๊ทธ์ธ์ ์ํ ๋ค๋ฅธ mutation์ ์คํํด์ผ ํฉ๋๋ค. ๋๊ธ์ ์ถ๊ฐํ ์ ์๋๋ก ํ๊ธฐ ์ํด์์
๋๋ค. ์๋ GraphiQL ํด๋ผ์ด์ธํธ์์ ใRunใ ๋ฒํผ์ ๋๋ฌ, ๋ฏธ๋ฆฌ ์์ฑ๋ ํ
์คํธ ์ฌ์ฉ์๋ก mutation ํ๋ loginUser๋ฅผ ์คํํด ์ฃผ์ธ์:
mutation LogUserIn {
loginUser(
by: { credentials: { usernameOrEmail: "test", password: "pass" } }
) {
id
name
}
}์ด์ ๋๊ธ์ ์ถ๊ฐํด ๋ณด๊ฒ ์ต๋๋ค. ์๋ Run ๋ฒํผ์ ๋๋ฌ, mutation ํ๋ addCommentToCustomPost๋ฅผ ์คํํ์ฌ ๊ฒ์๋ฌผ์ ๋๊ธ์ ์ถ๊ฐํด ์ฃผ์ธ์(๋๊ธ ํ
์คํธ๋ ํธ์งํ ์ ์์ต๋๋ค):
mutation AddComment {
addCommentToCustomPost(
input: { customPostID: 1459, comment: "Adding a comment: bla bla bla" }
) {
id
content
date
}
}์ด๋ฒ ์ฒซ ๋ฒ์งธ ๋ฆด๋ฆฌ์ค์์ ํ๋ฌ๊ทธ์ธ์๋ ๋ค์ mutation์ด ํฌํจ๋์ด ์์ต๋๋ค:
โ
createPost
โ
updatePost
โ
setFeaturedImageforCustomPost
โ
removeFeaturedImageforCustomPost
โ
addCommentToCustomPost
โ
replyComment
โ
loginUser
โ
logoutUser
2. Nested Mutations! ๐๐
Nested mutations๋ GraphQL์ root ํ์ ์ด์ธ์ ํ์ ์ ๋ํด mutation์ ์คํํ ์ ์๋ ๊ธฐ๋ฅ์ ๋๋ค.
์ด ๊ธฐ๋ฅ์ GraphQL ์คํ์ ์ถ๊ฐ๊ฐ ์์ฒญ๋ ๋ฐ ์์ผ๋, ์์ง ์น์ธ๋์ง ์์์ต๋๋ค(์์ผ๋ก๋ ์น์ธ๋์ง ์์ ์๋ ์์ต๋๋ค). ๊ทธ๋์ Gato GraphQL์ Nested Mutations ๋ชจ๋์ ํตํด ์ตํธ์ธ ๊ธฐ๋ฅ์ผ๋ก ์ง์์ ์ถ๊ฐํ๊ณ ์์ต๋๋ค.
ํ๋ฌ๊ทธ์ธ์ ๋ค์ ๋ ๊ฐ์ง ๋์์ ์ง์ํฉ๋๋ค:
- ํ์ค GraphQL ๋์(์ฆ, root ํ์ ์ mutation ํ๋๋ฅผ ์ถ๊ฐํ๋ ๊ฒ), ๊ธฐ๋ณธ๊ฐ
- Nested mutations, ์ตํธ์ธ์ผ๋ก
์๋ฅผ ๋ค์ด, ์์ ์ฟผ๋ฆฌ๋ ๋ค์ ์ฟผ๋ฆฌ๋ก๋ ์คํํ ์ ์์ต๋๋ค. ์ด ์ฟผ๋ฆฌ์์๋ ๋จผ์ Root.post๋ก ๊ฒ์๋ฌผ์ ๊ฐ์ ธ์จ ๋ค์, Post.addComment๋ก ๋๊ธ์ ์ถ๊ฐํฉ๋๋ค:
mutation AddComment {
post(by: { id: 1459 }) {
addComment(
input: {
comment: "Notice how field `addCommentToCustomPost` under the `Root` type is renamed as `addComment` under the `Post` type? The schema got neater!"
}
) {
id
content
date
}
}
}Mutation์ ๋ค๋ฅธ mutation์ ๊ฒฐ๊ณผ์ ๋ํด์๋ ๋ฐ์ดํฐ๋ฅผ ์์ ํ ์ ์์ต๋๋ค. ์๋ ์ฟผ๋ฆฌ์์๋ ๋จผ์ Root.post๋ก ๊ฒ์๋ฌผ์ ๊ฐ์ ธ์จ ํ, mutation Post.addComment๋ฅผ ์คํํ์ฌ ์์ฑ๋ ๋๊ธ ๊ฐ์ฒด๋ฅผ ์ป๊ณ , ๋ง์ง๋ง์ผ๋ก ๊ทธ ๋๊ธ์ ๋ํด mutation Comment.reply๋ฅผ ์คํํฉ๋๋ค:
mutation AddCommentAndResponse {
post(by: { id: 1459 }) {
id
title
addComment(input: { comment: "Isn't this awesome?" }) {
id
date
content
reply(input: { comment: "I think so!" }) {
id
date
content
}
}
}
}์ ๋ง ์ ์ฉํฉ๋๋ค! ๐ (๋์ผํ ๋์์ ๋จ์ผ ์ฟผ๋ฆฌ์์ ์คํํ๋ ๋์์ ์ธ ๋ฐฉ๋ฒ์ @export ๋๋ ํฐ๋ธ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์
๋๋คโฆ ํฅํ ๋ธ๋ก๊ทธ ๊ฒ์๋ฌผ์์ ๋ ๊ฐ์ง๋ฅผ ๋น๊ตํ ์์ ์
๋๋ค).
์ด๋ฒ ์ฒซ ๋ฒ์งธ ๋ฆด๋ฆฌ์ค์์ ํ๋ฌ๊ทธ์ธ์๋ ๋ค์ mutation์ด ํฌํจ๋์ด ์์ต๋๋ค:
โ
CustomPost.update
โ
CustomPost.setFeaturedImage
โ
CustomPost.removeFeaturedImage
โ
CustomPost.addComment
โ
Comment.reply
ํ์ค ๋๋ nested? ์๋๋ฉด ๋ ๋ค?
์์ฌ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉํ๋ GraphQL API๊ฐ ์๊ณ , ์ด๊ฒ์ด ํด๋ผ์ด์ธํธ์๊ฒ๋ ๊ณต๊ฐ๋์ด ์๋ค๊ณ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค. Nested mutations๋ฅผ ํ์ฑํํ๊ณ ์ถ์ง๋ง, ๋นํ์ค ๊ธฐ๋ฅ์ด๋ฏ๋ก ํด๋ผ์ด์ธํธ์๊ฒ๋ ์ ์ฉํ๊ณ ์ถ์ง ์์ ๊ฒฝ์ฐ๋ ์์ ๊ฒ์ ๋๋ค.
์ข์ ์์์ด ์์ต๋๋ค: ๊ทธ๊ฒ์ด ๊ฐ๋ฅํฉ๋๋ค.
Schema Configuration์ ใMutation Schemeใ ์น์ ์ ์ถ๊ฐํ์ต๋๋ค. ์ด ์น์ ์ Custom Endpoints์ Persisted Queries์ ์คํค๋ง๋ฅผ ์ปค์คํฐ๋ง์ด์งํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค:

์ด๋ฅผ ํตํด nested mutations๋ฅผ ๋ชจ๋ ๊ณณ์์ ๋นํ์ฑํํ๋ฉด์, ์์ฌ ์ ํ๋ฆฌ์ผ์ด์ ๋ง ์ฌ์ฉํ๋ ํน์ custom endpoint์์๋ง ํ์ฑํํ ์ ์์ต๋๋ค. ๐ช
root ํ์ ์์ ์ค๋ณต ํ๋ ์ ๊ฑฐํ๊ธฐ
Nested mutations๋ฅผ ์ฌ์ฉํ๋ฉด mutation ํ๋๊ฐ ์คํค๋ง์ ๋ ๋ฒ ์ถ๊ฐ๋ ์ ์์ต๋๋ค:
- root ํ์ ์๋์ ํ ๋ฒ
- ํน์ ํ์ ์๋์ ํ ๋ฒ
์๋ฅผ ๋ค์ด, ๋ค์ ํ๋๋ค์ ์๋ก์ ใ์ค๋ณตใ์ผ๋ก ๋ณผ ์ ์์ต๋๋ค:
Root.updatePostPost.update
Gato GraphQL์์๋ ๋ ๋ค ์ ์งํ๊ฑฐ๋, root ํ์ ์ ์ค๋ณต ํ๋๋ฅผ ์ ๊ฑฐํ๋ ๊ฒ์ ์ ํํ ์ ์์ต๋๋ค.
๋ค์ 3๊ฐ์ง ์คํค๋ง๊ฐ ์์ต๋๋ค:
- ํ์ค ๋์:
์ฟผ๋ฆฌ ์ฒ๋ฆฌ์QueryRootํ์ ์, mutation ์ฒ๋ฆฌ์MutationRootํ์ ์ ์ฌ์ฉํฉ๋๋ค - ์ค๋ณต mutation ํ๋๋ฅผ ์ ์งํ๋ nested mutations:
๋จ์ผRootํ์ ์ด ์ฟผ๋ฆฌ์ mutation์ ์ฒ๋ฆฌํ๋ฉฐ, ์ด ํ์ ์ ์ค๋ณต mutation ํ๋๋ ์ ์ง๋ฉ๋๋ค - root ํ์
์์ ์ค๋ณต mutation ํ๋๋ฅผ ์ ๊ฑฐํ๋ nested mutations:
์์ ๋์ผํ์ง๋ง,Rootํ์ ์์ ๋ชจ๋ ์ค๋ณต mutation ํ๋๋ฅผ ์ ๊ฑฐํฉ๋๋ค
โฑ ์ฐธ๊ณ ๋ก 1, ์ด 3๊ฐ์ง ์คํค๋ง๋ ๋ชจ๋ ๋์ผํ ์๋ํฌ์ธํธ๋ฅผ ์ฌ์ฉํ์ง๋ง, URL ํ๋ผ๋ฏธํฐ ?mutation_scheme์ standard, nested, lean_nested๋ก ๋ณ๊ฒฝํ์ฌ ์ ํํ ์ ์์ต๋๋ค. ์ด๊ฒ์ GraphQL ์๋ฒ๊ฐ code-first ์ ๊ทผ ๋ฐฉ์์ ๋ฐ๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฅํฉ๋๋ค. ๐ค
โฑ ์ฐธ๊ณ ๋ก 2, ์ด ์ต์ ๋ค์ Schema configuration(์์ ํ์๋จ)์ ใMutation Schemeใ ์น์ ์์ ์ ํํ ์ ์์ต๋๋ค. ๋ฐ๋ผ์ ๊ฐ๋ณ custom endpoints์ persisted queries์ ์ ์ฉํ ๋์๋ ๊ฒฐ์ ํ ์ ์์ต๋๋ค. ๐
์ด์ v0.8์ ์ค๋นํ ์๊ฐ์ ๋๋ค! ๐