Запрос данных плагинов
Запрос данных плагиновJetEngine

JetEngine

Примеры queries для взаимодействия с данными плагина JetEngine от Crocoblock.

Полное описание API (корневые поля, тип JetEngineCCTEntry, filter/pagination/sort, приведение типов полей) см. в справочнике расширения JetEngine CCT.

Список записей CCT

Запросите все записи для CCT, указав его slug. Свойства записи и значения полей 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

Получите одну запись CCT по slug CCT и числовому ID записи.

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

Поля записи и даты

Каждая запись предоставляет неявные поля (id, authorID, singleCustomPostID, даты и др.) и значения полей 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: фильтрация по ids или по search (поле, значение, оператор). Доступные операторы: EQUALS (по умолчанию) и LIKE.

query JetEngineCCTEntriesWithFilter {
  # Фильтр по IDs
  countByIds: jetengineCCTEntryCount(cctSlug: "sample_cct", filter: { 
    ids: [1, 3] 
  })
  entriesByIds: jetengineCCTEntries(cctSlug: "sample_cct", filter: { 
    ids: [1, 3] 
  }) {
    id
  }
 
  # Фильтр по полю (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")
  }
 
  # Фильтр по полю (LIKE)
  entriesByTextareaLike: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
    search: [{ field: "textarea", value: "description", operator: LIKE }] 
  }) {
    id
    textarea: fieldValue(slug: "textarea")
  }
 
  # Комбинация ids + search
  entriesByIdsAndSearch: jetengineCCTEntries(cctSlug: "sample_cct", filter: {
    ids: [1, 4],
    search: [{ field: "textarea", value: "description", operator: LIKE }] 
  }) {
    id
    textarea: fieldValue(slug: "textarea")
  }
}

Пагинация и сортировка

Запросы списка принимают pagination: { limit, offset } и sort: { by, order }. Сортировка возможна по встроенным ключам (_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 и sort в запросах списка; подсчёт принимает только 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")
  }
}