The third video in my series on using GraphQL with Sitecore is now online. In this video, I look at variables, built in fields, and the use of Fragments to improve query re-use.
Hope that people find it useful.
The third video in my series on using GraphQL with Sitecore is now online. In this video, I look at variables, built in fields, and the use of Fragments to improve query re-use.
Hope that people find it useful.
I’m pleased to release the second video in my series on using GraphQL with Sitecore. In this second video, I look at Item Queries and strong typing of items and fields.
Hope that people find it useful.
Recently I needed to expose a GraphQL query that accepted a list of Sitecore item IDs and returned the item data for those IDs. I wanted to use the Content Search API for efficiency reasons and because the items might not all be colocated in a folder.
Out of the box, the Sitecore GraphQL Search query does not allow you to do this, but a look into the GraphQL assembly revealed that the ListGraphType might do the job.
The resulting extensions to Sitecore.Services.GraphQL.Content.Queries.SearchQuery looked like this:
public class MySearchQuery : Sitecore.Services.GraphQL.Content.Queries.SearchQuery
{
public MySearchQuery()
{
Arguments.Add(new QueryArgument<ListGraphType<StringGraphType>>()
{
Name = "itemIds",
Description = "Filter by Sitecore item IDs"
});
}
//override the ContentSearchResults method here...
}
The GraphQL query was then able to pass in an array of item IDs which looked something like this:
query ExtendedSearch {
searchItemsById(itemIds:["6a6f0d75-2a1d-4f70-b639-622d308d9e11","{EF1848D8-6C43-4E52-A04F-287A12E19D12}"]) {
results {
items {
item {
id
field(name:"myItemField"){
value
}
}
}
}
}
}
One thing to note is that, although you are passing in a Guid like “6a6f0d75-2a1d-4f70-b639-622d308d9e11”, the Sitecore GraphQL content search results will come back with a value like “6A6F0D752A1D4F70B639622D308D9E11”.
Today I released Part 1 of a video series on using GraphQL with Sitecore. In this first part, I cover getting up and running with GraphQL through:
In later videos we’ll dig deeper into configuration, item and search queries, fragments, integrated GraphQL, and extending and customising GraphQL in the context of Sitecore.
Hope that people find it useful.