JetEngine
Các ví dụ về queries để tương tác với dữ liệu từ plugin JetEngine của Crocoblock.
Để xem toàn bộ API (root fields, kiểu JetEngineCCTEntry, filter/pagination/sort, field casts), hãy xem tài liệu tham khảo extension JetEngine CCT.
Liệt kê các mục CCT
Truy vấn tất cả các mục của một CCT bằng cách cung cấp slug của nó. Bạn có thể yêu cầu thuộc tính của mục và giá trị các trường CCT thông qua fieldValues hoặc fieldValue(slug:).
query JetEngineCCTEntries($cctSlug: String!) {
jetengineCCTEntryCount(cctSlug: $cctSlug)
jetengineCCTEntries(cctSlug: $cctSlug) {
id
cctSlug
status
authorID
author {
id
name
}
singleCustomPostID
singleCustomPost {
id
title
customPostType
}
createdDate
createdDateStr
modifiedDate
modifiedDateStr
fieldValues
label_text: fieldValue(slug: "label_text")
textarea: fieldValue(slug: "textarea")
number: fieldValue(slug: "number")
switcher: fieldValue(slug: "switcher")
gallery: fieldValue(slug: "gallery")
}
}Một mục CCT đơn lẻ
Lấy một mục CCT theo slug của CCT và ID số của mục đó.
query JetEngineCCTEntry($cctSlug: String!, $id: ID!) {
jetengineCCTEntry(cctSlug: $cctSlug, by: { id: $id }) {
id
uniqueID
cctSlug
status
authorID
author {
id
name
}
singleCustomPostID
singleCustomPost {
id
title
customPostType
}
createdDate
createdDateStr
modifiedDate
modifiedDateStr
fieldValues
label_text: fieldValue(slug: "label_text")
textarea: fieldValue(slug: "textarea")
repeater: fieldValue(slug: "repeater")
}
}Các trường mục và ngày tháng
Mỗi mục hiển thị các trường ngầm định (id, authorID, singleCustomPostID, ngày tháng, v.v.) và giá trị các trường CCT. Sử dụng createdDateStr / modifiedDateStr với tham số format tùy chọn để lấy chuỗi ngày được định dạng.
query JetEngineCCTEntryFields {
jetengineCCTEntry(cctSlug: "sample_cct", by: { id: 1 }) {
id
uniqueID
cctSlug
status
singleCustomPostID
singleCustomPost {
id
title
customPostType
}
authorID
author {
id
name
}
createdDate
createdDateStr
formattedCreatedDateStr: createdDateStr(format: "d/m/Y")
modifiedDate
modifiedDateStr
formattedModifiedDateStr: modifiedDateStr(format: "d/m/Y")
fieldValues
label_text: fieldValue(slug: "label_text")
number: fieldValue(slug: "number")
}
}Lọc các mục CCT
Các queries liệt kê và đếm hỗ trợ tham số filter: lọc theo ids hoặc theo search (trường, giá trị, toán tử). Các toán tử bao gồm EQUALS (mặc định) và LIKE.
query JetEngineCCTEntriesWithFilter {
# Lọc theo IDs
countByIds: jetengineCCTEntryCount(cctSlug: "sample_cct", filter: {
ids: [1, 3]
})
entriesByIds: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
ids: [1, 3]
}) {
id
}
# Lọc theo trường (EQUALS)
entriesByAuthor: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
search: [{ field: "cct_author_id", value: 1, operator: EQUALS }]
}) {
id
authorID
}
entriesByLabel: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
search: [{ field: "label_text", value: "Some label" }]
}) {
id
label_text: fieldValue(slug: "label_text")
}
# Lọc theo trường (LIKE)
entriesByTextareaLike: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
search: [{ field: "textarea", value: "description", operator: LIKE }]
}) {
id
textarea: fieldValue(slug: "textarea")
}
# Kết hợp ids + search
entriesByIdsAndSearch: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
ids: [1, 4],
search: [{ field: "textarea", value: "description", operator: LIKE }]
}) {
id
textarea: fieldValue(slug: "textarea")
}
}Phân trang và sắp xếp
Các queries liệt kê chấp nhận pagination: { limit, offset } và sort: { by, order }. Sắp xếp theo các khóa tích hợp như _ID, cct_created, cct_modified, hoặc theo bất kỳ slug trường CCT nào.
query JetEngineCCTEntriesWithPagination {
entriesWithLimit: jetengineCCTEntries(cctSlug: "sample_cct", pagination: { limit: 2 }) {
id
createdDate
textarea: fieldValue(slug: "textarea")
}
entriesPage2: jetengineCCTEntries(cctSlug: "sample_cct", pagination: { limit: 1, offset: 1 }) {
id
createdDate
textarea: fieldValue(slug: "textarea")
}
entriesSortByCreatedDesc: jetengineCCTEntries(cctSlug: "sample_cct", sort: { by: "cct_created", order: DESC }) {
id
createdDate
textarea: fieldValue(slug: "textarea")
}
entriesSortByIdAsc: jetengineCCTEntries(cctSlug: "sample_cct", sort: { by: "_ID", order: ASC }) {
id
textarea: fieldValue(slug: "textarea")
}
}Lọc kết hợp phân trang
Kết hợp filter, pagination và sort trong các queries liệt kê; count chỉ chấp nhận filter.
query JetEngineCCTEntriesFilterAndPagination {
jetengineCCTEntryCount(
cctSlug: "sample_cct"
filter: { search: [{ field: "textarea", value: "description", operator: LIKE }] }
)
jetengineCCTEntries(
cctSlug: "sample_cct"
filter: { search: [{ field: "textarea", value: "description", operator: LIKE }] }
pagination: { limit: 10, offset: 0 }
sort: { by: "cct_created", order: DESC }
) {
id
textarea: fieldValue(slug: "textarea")
}
}