Content queries
Contents
Use get to retrieve a known content item, getChildren to list items below a path, and queryDsl to search across the project. The HeadlessCms reference lists their arguments and return types.
These examples query published content in myproject. Replace the project name and content paths with your own, and send the queries using the request format on the Usage page.
Retrieve an item
The key argument accepts a content ID or a path within the project:
{
guillotine(project: "myproject", branch: "master") {
get(key: "/my-site/posts/first-post") {
_id
displayName
type
}
}
}
Query by content type
Enonic’s Query DSL supports filtering, ranked search, aggregations and highlighting. This query filters on the content type and returns up to ten posts:
{
guillotine(project: "myproject", branch: "master") {
queryDsl(
query: {
term: {
field: "type"
value: { string: "com.example.myapp:post" }
}
}
first: 10
) {
_id
displayName
... on com_example_myapp_Post {
data {
title
}
}
}
}
}
This example assumes a com.example.myapp:post content type with a title field. Its content type identifier includes the owning app’s namespace. Guillotine exposes its form fields under data on the generated GraphQL type, here com_example_myapp_Post.
Use an inline fragment (… on TypeName) to select fields belonging to a particular content type. Check the generated type and field names in Playground when adapting the query to your model.
Pagination
List fields such as getChildren and queryDsl accept first to limit the number of items and offset to skip items. For example, this requests the second group of ten children, sorted by display name:
{
guillotine(project: "myproject", branch: "master") {
getChildren(key: "/my-site/posts", first: 10, offset: 10, sort: "displayName ASC") {
_id
displayName
}
}
}
For cursor pagination and result metadata, use the corresponding connection fields, such as getChildrenConnection and queryDslConnection. See ContentConnection and QueryDSLContentConnection for the response structures.
Cursor pagination
This query retrieves a page of ten children and the information needed to request the next page:
query ChildrenPage($after: String) {
guillotine(project: "myproject", branch: "master") {
getChildrenConnection(
key: "/my-site/posts"
first: 10
after: $after
sort: "displayName ASC"
) {
totalCount
edges {
node {
_id
displayName
}
}
pageInfo {
endCursor
hasNext
}
}
}
}
For the first request, send these variables:
{"after": null}
Read the items from data.guillotine.getChildrenConnection.edges, where each node is a content item. If pageInfo.hasNext is true, copy pageInfo.endCursor into the next request’s after variable and send the same query again. For example, if the returned cursor is "OQ==", the next variables are:
{"after": "OQ=="}
Repeat until hasNext is false. Treat cursors as opaque values: use the value returned by the API rather than calculating it. Keep the project, branch, key and sorting unchanged while paging; start again with after: null when changing them. Content changes between requests can shift the results, so pagination does not provide a snapshot of the content.