๐ Gato GraphQL์ด ์ด์ Advanced Custom Fields (ACF)๋ฅผ ์์ ํ ์ง์ํฉ๋๋ค!
์ง๋์ฃผ์ ์ถ์๋ Gato GraphQL v11.3์์๋ ๋ฉํ ๋ฎคํ
์ด์
์ด ์ ๊ณต๋์์ต๋๋ค.
๋ฉํ ํ๋์ ๊ฒฐํฉํ๊ณ PRO ํ์ฅ ๊ธฐ๋ฅ์ด ์ ๊ณตํ๋ ๊ธฐ๋ฅ๊ณผ ์ฐ๋ํจ์ผ๋ก์จ, ๋ฉํ ๋ฎคํ ์ด์ ์ ์ฌ์ฉํ์ฌ Advanced Custom Fields (ACF) ํ๋ฌ๊ทธ์ธ๊ณผ ์์ ํ ์ํธ์์ฉํ ์ ์๊ฒ ๋์์ต๋๋ค. ์ปค์คํ ํ๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ์์ ํ๋ ๊ฒ ๋ชจ๋ ๊ฐ๋ฅํฉ๋๋ค.
์ฆ, Gato GraphQL์ ์ด์ ACF๋ฅผ ์์ ํ ์ง์ํฉ๋๋ค! ๐๐ฅณ๐๐พ๐๐๐ป
๋ค์์ ACF๊ฐ ์ง์ํ๋ ๋ชจ๋ ํ๋ ํ์ ์ ๋ํด ์ปค์คํ ํ๋๋ฅผ ๊ฐ์ ธ์ค๊ณ ์์ ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ฃผ๋ ์ฌ๋ฌ ์ฟผ๋ฆฌ์ ๋๋ค.

๊ธฐ๋ณธ ํ๋ ํ์ ์ฟผ๋ฆฌ
ACF์ ๊ธฐ๋ณธ ํ๋ ํ์
์ metaValue ํ๋๋ฅผ ์ฌ์ฉํ์ฌ ์ง์ ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
query GetPost {
post(by: { id: 1 }) {
text: metaValue(key: "text_field")
textarea: metaValue(key: "textarea_field")
number: metaValue(key: "number_field")
range: metaValue(key: "range_field")
email: metaValue(key: "email_field")
url: metaValue(key: "url_field")
password: metaValue(key: "password_field")
}
}์ฝํ ์ธ ํ๋ ํ์ ์ฟผ๋ฆฌ
์ปค์คํ
ํ๋๊ฐ ๊ด๊ณ(์: ์ด๋ฏธ์ง๋ ํ์ผ)์ธ ๊ฒฝ์ฐ, ๋ฉํ ํ๋์์ ID๋ฅผ ๋ด๋ณด๋ด๊ณ ์ดํ ์ฟผ๋ฆฌ์์ ํด๋น ์ํฐํฐ(Media ํ์
)๋ฅผ ๋ฐ๋ก ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
๊ทธ ์ธ์ ๊ฒฝ์ฐ์๋ ๋จ์ ํ๋ ํ์
์ด๋ฏ๋ก metaValue๋ฅผ ์ฌ์ฉํ์ฌ ์ง์ ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
query GetPostDataAndExportRelationships {
post(by: { id: 1 }) {
# Image field type
imageId: metaValue(key: "image_field")
@export(as: "imageId")
# File field type
fileId: metaValue(key: "file_field")
@export(as: "fileId")
# WYSIWYG editor field type
wysiwyg_editor: metaValue(key: "wysiwyg_editor_field")
# Oembed field type
oembed: metaValue(key: "oembed_field")
}
}
query QueryPostRelationships
@depends(on: "GetPostDataAndExportRelationships")
{
# Query the image
relationshipImage: mediaItem(by: { id: $imageId }) {
id
src
}
# Query the file
relationshipFile: mediaItem(by: { id: $fileId }) {
id
src
}
}์ ํ ํ๋ ํ์ ์ฟผ๋ฆฌ
์ ํ ํ๋ ํ์
์ metaValue๋ฅผ ์ฌ์ฉํ์ฌ ๋จ์ ํ๋ ํ์
์ฒ๋ผ ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
ACF๋ ๊ฐ์ ๋ฐฐ์ด์ JSON ๋ฌธ์์ด๋ก ์ธ์ฝ๋ฉํ์ฌ ๋จ์ผ ํญ๋ชฉ์ ์ ์ฅํ๊ธฐ ๋๋ฌธ์, ๋ฐฐ์ด์ ๊ฐ์ ธ์ค๋ ค๋ฉด metaValues ๋์ metaValue ํ๋๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
๋ถ๋ฆฌ์ธ ๊ฐ์ ๊ฒฝ์ฐ _equals ํ๋๋ฅผ ์ฌ์ฉํ์ฌ String์์ Boolean์ผ๋ก ํ๋ณํํฉ๋๋ค.
query GetPost {
post(by: { id: 1 }) {
# Select field type - Whether a single or multiple values, we always use `metaValue`
select: metaValue(key: "select_field")
multiSelect: metaValue(key: "multi_select_field")
# Checkbox field type
checkbox: metaValue(key: "checkbox_field")
# Radio button field type
radioButton: metaValue(key: "radio_button_field")
# Button group field type
buttonGroup: metaValue(key: "button_group_field")
# True/False field type
trueFalseAsString: metaValue(key: "true_false_field")
trueFalse: _equals(value1: $__trueFalseAsString, value2: "1")
}
}๊ด๊ณํ ํ๋ ํ์ ์ฟผ๋ฆฌ
์ปค์คํ
ํ๋๊ฐ ๊ด๊ณ(์: ๊ฒ์๋ฌผ, ์ฌ์ฉ์, ํ์๋
ธ๋ฏธ ๋ฑ)์ธ ๊ฒฝ์ฐ, ๋ฉํ ํ๋์์ ID๋ฅผ ๋ด๋ณด๋ด๊ณ ์ดํ ์ฟผ๋ฆฌ์์ ํด๋น ์ํฐํฐ(Post, User, Taxonomy ํ์
๋ฑ)๋ฅผ ๋ฐ๋ก ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
๊ทธ ์ธ์ ๊ฒฝ์ฐ์๋ ๋จ์ ํ๋ ํ์
์ด๋ฏ๋ก metaValue๋ฅผ ์ฌ์ฉํ์ฌ ์ง์ ์ฟผ๋ฆฌํ ์ ์์ต๋๋ค.
query GetPostDataAndExportRelationships {
post(by: { id: 1 }) {
link: metaValue(key: "link_field")
# Post Object field type
post_object: metaValue(key: "post_object_field")
@export(as: "post_object_id")
# Multiple Post Object field type
post_objects: metaValue(key: "post_objects_field")
@export(as: "post_object_ids")
# Page Link field type
page_link: metaValue(key: "page_link_field")
@export(as: "page_link_id")
# Multiple Page Link field type
page_links: metaValue(key: "page_links_field")
@export(as: "page_link_ids")
# Relationship field type
relationships: metaValue(key: "relationship_field")
@export(as: "relationship_ids")
# Taxonomy field type
categoryTaxonomy: metaValue(key: "category_taxonomy_field")
@export(as: "category_taxonomy_ids")
tagTaxonomy: metaValue(key: "tag_taxonomy_field")
@export(as: "tag_taxonomy_ids")
# User field type
user: metaValue(key: "user_field")
@export(as: "user_id")
# Multiple User field type
users: metaValue(key: "users_field")
@export(as: "user_ids")
}
}
query QueryPostRelationships
@depends(on: "GetPostDataAndExportRelationships")
{
# Query the post
postObject: customPost(by: { id: $post_object_id }, status: any) {
id
title
}
# Query the list of posts
postObjects: customPosts(filter: { ids: $post_object_ids, status: any }, pagination: { limit: -1 }) {
id
title
}
# Query the page
pageLink: page(by: { id: $page_link_id }, status: any) {
id
title
}
# Query the list of pages
pageLinks: pages(filter: { ids: $page_link_ids, status: any }, pagination: { limit: -1 }) {
id
title
}
# Query the relationship post
relationships: customPosts(filter: { ids: $relationship_ids, status: any }, pagination: { limit: -1 }) {
id
title
}
# Query the list of categories
categoryTaxonomy: categories(filter: { ids: $category_taxonomy_ids }, taxonomy: "category") {
id
name
}
# Query the list of tags
tagTaxonomy: tags(filter: { ids: $tag_taxonomy_ids }, taxonomy: "post_tag") {
id
name
}
# Query the user
user: user(by: { id: $user_id }) {
id
name
}
# Query the list of users
users: users(filter: { ids: $user_ids }, pagination: { limit: -1 }) {
id
name
}
}๋ ์ง ํ๋ ํ์ ์ฟผ๋ฆฌ
๋ ์ง๋ "YMD" ํ์์ ๋ฌธ์์ด(์: "20240320")๋ก ์ ์ฅ๋๊ธฐ ๋๋ฌธ์, ํ์์คํฌํ๋ก ํ์ฑํ ํ _date ํจ์์ ์ ๋ฌํด์ผ ํฉ๋๋ค.
query GetPost {
post(by: { id: 1 }) {
# Date Picker field
dateAsString: metaValue(key: "date_picker_field")
dateYear: _strSubstr(string: $__dateAsString, offset: 0, length: 4)
dateMonth: _strSubstr(string: $__dateAsString, offset: 4, length: 2)
dateDay: _strSubstr(string: $__dateAsString, offset: 6, length: 2)
dateAsTimestamp: _makeTime(year: $__dateYear, month: $__dateMonth, day: $__dateDay, hour: 0, minute: 0, second: 0)
date: _date(format: "Y-m-d", timestamp: $__dateAsTimestamp)
# Date Time Picker field
dateTime: metaValue(key: "date_time_picker_field")
# Time Picker field
timeAsString: metaValue(key: "time_picker_field")
timeHours: _strSubstr(string: $__timeAsString, offset: 0, length: 2)
timeMinutes: _strSubstr(string: $__timeAsString, offset: 3, length: 2)
timeSeconds: _strSubstr(string: $__timeAsString, offset: 6, length: 2)
googleMap: metaValue(key: "google_map_field")
colorPicker: metaValue(key: "color_picker_field")
}
}๋ชจ๋ ํ๋ ํ์ ๋ฎคํ ์ด์
๋ฉํ ํ๋๋ฅผ ์ฌ์ฉํ์ฌ ACF ์ปค์คํ ํ๋๋ฅผ ์ถ๊ฐ, ์์ , ์ญ์ ํฉ๋๋ค.
์ด ์ฟผ๋ฆฌ๋ ๋จ์ผ JSON ๊ฐ์ฒด๋ฅผ updatePost ๋ฎคํ
์ด์
์ ์ ๋ฌํ์ฌ ์ฌ๋ฌ ACF ์ปค์คํ
ํ๋๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค.
(JSON์๋ ํญ๋ชฉ์ด ๋จ์ผ ๊ฐ์ด๋๋ผ๋ ๊ฐ์ ๋ฐฐ์ด์ด ํฌํจ๋์ด ์์์ ์ ์ํ์ธ์.)
mutation UpdatePost($postId: ID!) {
updatePost(
input: {
id: $postId
meta: {
text_field: ["New text value"],
textarea_field: ["New textarea value"],
select_field: ["New select value"],
multi_select_field: ["Choice 1", "Choice 2"],
number_field: [42],
date_picker_field: ["20240320"],
}
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
text: metaValue(key: "text_field")
textarea: metaValue(key: "textarea_field")
select: metaValue(key: "select_field")
multiSelect: metaValues(key: "multi_select_field")
number: metaValue(key: "number_field")
date: metaValue(key: "date_picker_field")
}
}
}์ด ์ฟผ๋ฆฌ๋ updateCustomPostMeta ๋ฎคํ
์ด์
์ ์ฌ์ฉํ์ฌ ACF ์ปค์คํ
ํ๋๋ฅผ ์ผ๊ด ์
๋ฐ์ดํธํฉ๋๋ค.
mutation UpdatePost($postId: ID!) {
updateCustomPostMetas(inputs: [
{ id: $postId, key: "text_field", value: "New text value" },
{ id: $postId, key: "textarea_field", value: "New textarea value" },
{ id: $postId, key: "select_field", value: "New select value" },
{ id: $postId, key: "multi_select_field", value: ["Choice 1", "Choice 2"] },
{ id: $postId, key: "number_field", value: 42 },
{ id: $postId, key: "date_picker_field", value: "20240320" },
]) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
customPost {
__typename
id
text: metaValue(key: "text_field")
textarea: metaValue(key: "textarea_field")
select: metaValue(key: "select_field")
multiSelect: metaValues(key: "multi_select_field")
number: metaValue(key: "number_field")
date: metaValue(key: "date_picker_field")
}
}
}