Querying¶
Example queries facilitating QuerySetList
parameters may be:
QuerySetList¶
Searching¶
If the model is enabled with the Wagtail Search, searchQuery
parameter
can be used to pass a search query as an argument:
query {
pages {
locations {
locationPage(searchQuery:"test") {
id
title
}
}
}
}
Get a specific object¶
To get an object of a specific ID, the ID can be passed as an argument to the
id
parameter.
query($id: ID) {
pages {
locations {
locationPage(id: $id) {
id
title
}
}
}
}
Limit and offset¶
query {
pages {
locations {
locationPage(limit: 5, offset: 2) {
id
title
}
}
}
}
Order by¶
Order by will feed the string into the QuerySet’s order_by method. Multiple fields can be specified with a comma as a delimiter.
query {
pages {
locations {
locationPageByTitleAscending: locationPage(order:"title") {
id
title
}
locationPageByTitleDescending: locationPage(order:"-title") {
id
title
}
locationPageByTitleAndID: locationPage(order:"title,-id") {
id
title
}
}
}
}
Page Interface¶
wagtail_graphql.types.pages.PageInterface
defines base model pages and
methods that can be used on any page.
The commonly used Wagtail methods available on any page type are:
- Returning one
PageInterface
object: parent
specific
- Returning one
- Returning list of
PageInterface
instances: children
siblings
nextSiblings
previousSiblings
descendants
ancestors
- Returning list of
Pages query mixin¶
The pages query mixin adds two parameters to the standard QuerySetList
set:
depth
showInMenus
This allows to filter pages by depth or whether they are supposed to be shown in the menu. For example, to get a potential set of pages to be used in the header navigation, the following query may be used:
query {
pages {
wagtailcore {
page(depth: 3, showInMenus: true) {
id
title
pageType
}
}
}
}