GraphQL queries¶
Querying content¶
You can query a single content item or a list of content items using fields defined in the domain schema.
Get a content item¶
To get a specific content item by its content ID, location ID, or URL alias, use its relevant singular field, for example article
, folder
, or image
.
1 2 3 4 5 6 7 8 9 10 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
You can request any fields of the content item. In the example above, these are title
and author
.
You can also query the generic item
object.
The item
object references a content item, but you can also get its location information.
The query accepts locationId
, remoteId
, and urlAlias
as arguments.
1 2 3 4 5 |
|
Response:
1 2 3 4 5 6 7 |
|
Get language versions¶
To get fields of a content item in a specific language, use the language
argument.
The language must be configured for the current SiteAccess.
1 2 3 4 5 6 7 8 |
|
Response:
1 2 3 4 5 6 7 8 9 10 |
|
When you don't specify a language, the response contains the most prioritized translation.
Get a group of content items¶
To get a list of all content items of a selected type, use the plural field, for example, articles
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
Edges
edges
are used when querying plural fields to offer pagination.
Get content type information¶
To get the IDs and names of all Fields in the article
content type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
Querying Locations¶
You can get the Location object from any item by querying for _location
or _allLocations
.
When you use _location
, the API returns:
- the location specified in the
locationId
orurlAlias
argument - the location based on the current SiteAccess
- the main location
1 2 3 4 5 6 7 8 9 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
To query the URL alias of a content item, use _url
.
This returns the "best" URL alias for this content item based on its main Location and the current SiteAccess:
1 2 3 4 5 6 7 |
|
Response:
1 2 3 4 5 6 7 8 9 |
|
Getting children of a Location¶
To get a location's children, it's recommended to use the Query field.
Alternatively, you can query the children
property of an item
or content
object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
Querying products¶
You can query a single product, products of one type, or all products by providing criteria.
Note
GraphQL schema for product catalog is generated only when at least one product type exists in the system. If your queries fail, make sure you regenerated the schema.
To get a single product by its code:
1 2 3 4 5 6 7 8 9 10 11 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
To get products of a specific type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
To get all products, using specific criteria (in this case, unavailable products):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Filtering¶
To get all articles with a specific text:
1 2 3 4 5 6 7 8 9 10 11 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
To filter products based on content fields:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Querying product attributes¶
To filter products based on attributes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
If the attribute type (in this case, measure
) cannot be found in the schema, the response is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
You can also query attributes by providing the attribute type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Note
You need to use aliases (for example, sizeValue
) when querying attributes by the attribute type due to the conflicting return types.
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
Sorting¶
You can sort query results using sortBy
:
1 2 3 4 5 6 7 8 9 10 11 |
|
You can use an array of clauses as well. To reverse the item list, add _desc
after the clause:
1 |
|
Pagination¶
GraphQL offers cursor-based pagination for paginating query results.
You can paginate plural fields by using edges
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
This query returns the first three articles, ordered by their publication date.
If the current Connection
(list of results) isn't finished yet and there are more items to read, hasNextPage
is true
.
For the children
node, you can use the following pagination method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
In the response, number
contains page numbers, starting with 2 (because 1 is the default).
To request a specific page, provide the cursor
as an argument to children
:
1 |
|
Get Matrix field type¶
To get a Matrix field type with GraphQL, see Matrix field type reference.