GraphQL query examples
We have provided the following GraphQL query examples to give you an idea of how to use available operators in the GraphQL IDE. The graphQL schema provides an overview of how data is organized and structured in Content Hub ONE.
You must authenticate with an API key for all requests to the GraphQL APIs.
When working in the GraphQL IDE, you can use the DOCS tab to access additional guidance on writing queries.
Basic actions
These query examples illustrate basic actions for Content Hub ONE that show how to use precise criteria to fetch a variety of data, such as a specific hotel, a collection of hotels and destinations, or a series of images related to a destination.
Get items of a specific type
This sample query returns all content items of the Hotels content type.
Example
{
allHotels {
total
results {
name
id
}
}
}
Get item by ID
This sample query returns the name of the hotel with an ID
of ecoInn
. In a similar manner, you can fetch a media item by ID
.
Example
{
hotels(id: "ecoInn") {
name
}
}
Get associated media
This sample query returns the ID
and name of a hotel with an ID
of luxuryInn
, along with the file name and file type of the images associated with it.
Example
{
hotels(id: "luxuryInn") {
id
name
heroImage {
results {
name
fileType
}
}
}
}
Get related items
This sample query uses a GraphQL fragment to return the ID
and name
of related items that have the Destination content type.
Example
{
allHotels {
results {
name
relatedItems {
results {
... on Destination {
id
name
}
}
}
}
}
}
Get all taxonomy values for a specific taxonomy
This sample query returns the ID
of the taxonomy values that make up the taxonomy called amenities.
Example
{
allTaxonomy_amenities {
results {
id
}
}
}
Get content based on specific taxonomy values
This sample query returns the name of hotels where the amenities
taxonomy includes Wifi
or Air conditioning
. The query also returns the file name and file type of the images associated with the hotel, along with a list of the taxonomy value ID
for all available amenities.
Example
{
allHotels
(where:{
OR:[
{ amenities:{taxonomy_amenities_ids: "taxonomy_amenities_wifi"}}
{amenities:{taxonomy_amenities_ids: "taxonomy_amenities_airConditioning"}}
]})
{
results {
name
heroImage {
results {
id
name
fileType
}
}
amenities{
results{
id
}
}
}
}
}
Operators
These query examples illustrate how to use query operators to filter the data fetched.
AND operators
This sample query returns the id, name, industry, and creation date of items that have the Hotels content type, are part of the travel industry, and have a name containing the word eco.
Example
{
allHotels (
where: {
AND: [
{industry_contains: "travel"}
{name_contains:"eco"}
]
}
)
{
results{
id
name
industry
__sysCreatedAt
}
}
}
OR operators
This sample query returns the name, rating, and price per night of items that have the Hotels content type, and either cost less than 60 USD or have a rating of 3 stars.
Example
{
allHotels (
where: {
OR: [
{pricePerNight_lt: 60}
{ratingstars_eq:"3"}
]
}
)
{
results{
name
ratingstars
pricePerNight
__sysCreatedAt
}
}
}
Nested operators
This sample query uses nested operators to return items with the Hotels content type that satisfy the following conditions:
- The price per night for the hotel is less than 100 USD.
- The hotel rating is 4 or the industry is travel.
Example
{
allHotels (
where: {
AND: [
{pricePerNight_lt: 100}
{
OR: [
{ratingstars_eq:"4"}
{industry_eq:"travel"}
]
}
]
}
)
{
results{
name
pricePerNight
ratingstars
__sysCreatedAt
}
}
}
Arguments
The following examples use the arguments available on the where
clause in the Content Hub ONE GraphQL implementation.
anyOf
This sample query returns the ID
and title of any item with the Destination content type and an ID
that matches either japan or thailand.
Example
{
allDestination(
where: {id_anyOf: ["japan", "thailand"]})
{
total
results {
id
name
}
}
}
noneOf
This sample query returns the ID
and name of hotels with the Hotels content type that do not have an ID
that matches ecoInn or luxuryInn.
Example
{
allHotels(
where: {id_noneOf: ["ecoInn", "luxuryInn"]})
{
total
results {
id
name
}
}
}
Contains
This sample query returns the name and ID
of items with the Tour content type that have a name containing the ampersand (&) symbol.
Example
{
allTour(where: {name_contains: "&"
}) {
results {
name
id
}
}
}
Equals
This sample query returns the name and short description of items with the Hotels content type and a rating of 4 stars.
Example
{
allHotels(
where: {
ratingstars_eq: 4
} ) {
total
results {
name
shortDescription
}
}
}
Not Equal
This sample query returns the name, short description, and rating of items with the Hotels content type and a rating that is not 2.
Example
{
allHotels(
where: {
ratingstars_neq: 2
} ) {
total
results {
name
shortDescription
ratingstars
}
}
}
Less than
This sample query returns items with the Hotels content type that cost less than 55 USD per night.
Example
{
allHotels(where: {pricePerNight_lt: 55
}) {
results {
name
pricePerNight
}
}
}
Greater than
This sample query returns items with the Hotels content type that cost more than 75 USD per night.
Example
{
allHotels(where: {pricePerNight_gt: 75
}) {
results {
name
pricePerNight
}
}
}
Between
This sample query returns items with the Hotels content type that were created between June 1, 2023 and July 1, 2023.
Example
{
allHotels(where: {__sysCreatedAt_between: [
"2023-06-01T19:26:15.000Z"
"2023-07-01T19:26:15.000Z"]
}) {
results {
name
__sysCreatedAt
}
}
}
OrderBy
This sample query returns items with the Destination content type in descending order based on the system-defined field SYSCREATEDAT
, which is the date the item was created.
Example
{
allDestination(
orderBy: [
__SYSCREATEDAT_DESC
]
) {
results {
name
__sysCreatedAt
}
}
}
First
This sample query returns the first three items with the Destination content type.
Example
{
allDestination(
first: 3,
) {
results {
name
}
}
}
Total
This sample query returns the total number of items of type TourEvents that have a title containing the symbol "&".
Example
{
allTourEvents(
where: {
name_contains: "&"
} ) {
total
results {
name
}
}
}
Typename
This sample query returns items of type Hotels where the title contains either "hostel" or "comfort". For each item, it also returns a list of items that are associated using references.
Example
{
allHotels (
where: {
OR: [
{name_contains: "hostel"}
{name_contains:"comfort"}
]
}
)
{
results {
name
relatedItems
{
results{
... on Destination {
name
}
... on Tour {
name
}
contentType: __typename
}
}
}
}
}
Pagination
These query examples illustrate how to paginate the response body and how to fetch the next page of results.
PageInfo
This sample query returns the first three items of the type Destination. It uses the pageInfo
object to fetch information needed for pagination, including the endCursor
field, which indicates the final item in the response; and the hasNext
field, which indicates whether more results are available.
Example
{
allDestination(first:3)
{
results {
id
name
}
pageInfo {
endCursor
hasNext
}
}
}
After
This sample query returns the next three items of the type Destination after the endCursor
point of the previous example. It uses the pageInfo
type to fetch information needed for pagination, including the endCursor
field and hasNext
fields described in the previous example.
Example
{
allDestination(first:3, after:"eyJzZWFyY2hBZnRlciI6WyJtYWxheXNpYSIsIm1hbGF5c2lhIl0sImNvdW50IjozfQ==")
{
total
results {
id
name
}
pageInfo {
endCursor
hasNext
}
}
}
Sorting
These query examples illustrate how to fetch items and order the results.
Get items and sort in ascending order
This sample query returns the name of items of the type Destination. These results are sorted by title in ascending order.
Example
{
allDestination(
orderBy: NAME_ASC
) {
results {
name
}
}
}
Get items of various content types and sort in descending order
This sample query returns the name of all items of the type Destination, and the IDs of all the items with the type Tour, along with the total count of each. It sorts both sets of results in descending order.
Example
{
allDestination(
orderBy: NAME_DESC
) {
total
results {
name
}
}
allTour(
orderBy: ID_DESC
) {
total
results {
id
}
}
}
Transformations
These query examples illustrate how to fetch a media item and apply transformations to it.
Change width and height
This sample query locates a media item with an ID of GGp18w-IlkuCtj7A3G0i3g and returns the URL for a version of that item that has been resized to a specific width (500 pixels) and height (300 pixels).
Example
{
media(id: "GGp18w-IlkuCtj7A3G0i3g") {
name
fileUrl(transform: {
width: 500,
height:300,
})
}
}
Rotate
This sample query locates a media item with an ID of GGp18w-IlkuCtj7A3G0i3g and returns the URL for a version of that item that has been rotated 90 degrees.
Example
{
media(id: "GGp18w-IlkuCtj7A3G0i3g") {
name
fileUrl(transform: {
rotate: 90,
})
}
}