I thought I'd put up a friendly reminder for those who know, or some useful information for those who don't: using children
in your GraphQL will (by default) only return 10 items, however the children
keyword in Sitecore GraphQL is in fact a function! With this information you can find that you can filter and paginate your list of child items.
While the vast majority of examples you find are something like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query MyQuery($datasource: String!, $language: String!) { | |
datasource: item(path: $datasource, language: $language) { | |
# List children of given datasource | |
children { | |
results { | |
id | |
name | |
field(name: "MyCustomField") { | |
jsonValue | |
} | |
} | |
} | |
} | |
} |
You can actually write it as:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query MyQuery($datasource: String!, $language: String!) { | |
datasource: item(path: $datasource, language: $language) { | |
# List 20 children of given template under given datasource | |
children( | |
first: 20 | |
includeTemplateIDs: "{A6DDAC75-7D24-4BDB-B3F6-5F47FBB21379}" | |
# after: "endCursor" (see endCursor below) | |
# hasLayout: true | |
) | |
{ | |
pageInfo { | |
hasNext | |
endCursor | |
} | |
results { | |
id | |
name | |
field(name: "MyCustomField") { | |
jsonValue | |
} | |
} | |
} | |
} | |
} |
There really don't seem to be that many examples around which use these features of children
(though there are many showing similar parameters for search
), so hope this helps someone!
No comments:
Post a Comment