การ Query ข้อมูลปลั๊กอิน
การ Query ข้อมูลปลั๊กอินJetEngine

JetEngine

ตัวอย่าง queries สำหรับโต้ตอบกับข้อมูลจากปลั๊กอิน Crocoblock JetEngine

สำหรับ API ฉบับสมบูรณ์ (root fields, ประเภท JetEngineCCTEntry, filter/pagination/sort, field casts) โปรดดูที่ เอกสารอ้างอิง JetEngine CCT extension

แสดงรายการ CCT entries

ดึงข้อมูล entries ทั้งหมดของ CCT โดยระบุ slug สามารถร้องขอคุณสมบัติของ entry และค่าฟิลด์ CCT ผ่าน fieldValues หรือ 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")
  }
}

CCT entry เดียว

ดึงข้อมูล CCT entry หนึ่งรายการโดยระบุ CCT slug และ ID ตัวเลขของ entry

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")
  }
}

ฟิลด์ของ entry และวันที่

แต่ละ entry เปิดเผยฟิลด์โดยนัย (id, authorID, singleCustomPostID, วันที่ ฯลฯ) และค่าฟิลด์ CCT ใช้ createdDateStr / modifiedDateStr พร้อม format ที่เป็น option สำหรับสตริงวันที่ที่จัดรูปแบบแล้ว

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")
  }
}

กรอง CCT entries

การแสดงรายการและการนับรองรับ argument filter: กรองด้วย ids หรือด้วย search (field, value, operator) operators ที่รองรับได้แก่ EQUALS (ค่าเริ่มต้น) และ LIKE

query JetEngineCCTEntriesWithFilter {
  # Filter by IDs
  countByIds: jetengineCCTEntryCount(cctSlug: "sample_cct", filter: { 
    ids: [1, 3] 
  })
  entriesByIds: jetengineCCTEntries(cctSlug: "sample_cct", filter: { 
    ids: [1, 3] 
  }) {
    id
  }
 
  # Filter by field (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")
  }
 
  # Filter by field (LIKE)
  entriesByTextareaLike: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
    search: [{ field: "textarea", value: "description", operator: LIKE }] 
  }) {
    id
    textarea: fieldValue(slug: "textarea")
  }
 
  # Combine ids + search
  entriesByIdsAndSearch: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
    ids: [1, 4],
    search: [{ field: "textarea", value: "description", operator: LIKE }] 
  }) {
    id
    textarea: fieldValue(slug: "textarea")
  }
}

Pagination และการเรียงลำดับ

List queries รองรับ pagination: { limit, offset } และ sort: { by, order } เรียงลำดับด้วย keys ในตัวอย่างเช่น _ID, cct_created, cct_modified หรือ slug ของฟิลด์ CCT ใดก็ได้

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")
  }
}

ใช้ filter ร่วมกับ pagination

รวม filter, pagination และ sort ใน list queries ได้พร้อมกัน โดยการนับรองรับเฉพาะ 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")
  }
}