查询插件数据
查询插件数据JetEngine

JetEngine

Crocoblock 的 JetEngine 插件数据进行交互的 Query 示例。

完整 API(根字段、JetEngineCCTEntry 类型、filter/pagination/sort、字段类型转换),请参阅 JetEngine CCT 扩展参考

列出 CCT 条目

通过提供 slug 来查询某个 CCT 的所有条目。可以通过 fieldValuesfieldValue(slug:) 请求条目属性和 CCT 字段值。

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 条目

通过 CCT slug 和条目的数字 ID 获取单个 CCT 条目。

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

条目字段与日期

每个条目都公开隐式字段(idauthorIDsingleCustomPostID、日期等)以及 CCT 字段值。使用 createdDateStr / modifiedDateStr 并搭配可选的 format 参数来获取格式化的日期字符串。

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 条目

列表查询和计数查询都支持 filter 参数:可以通过 idssearch(字段、值、运算符)进行过滤。运算符包括 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")
  }
}

分页与排序

列表 Query 接受 pagination: { limit, offset }sort: { by, order } 参数。可以按内置键(如 _IDcct_createdcct_modified)或任意 CCT 字段 slug 进行排序。

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

过滤与分页的组合

在列表 Query 中可以组合使用 filterpaginationsort;计数查询仅接受 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")
  }
}