Based on my review of the decompiled Sitecore.Services.GraphQL.EdgeSchema.Services.SearchService
class (which is the service used by the Sitecore.Services.GraphQL.EdgeSchema.Queries.SearchQuery
query which responds to search
queries in GraphQL), it appears that you can use any field that is present in your Solr index, but a handful of standard fields get some special treatment.
The Solution
If you look in the Solr index (e.g. sitecore_master_index
) you will see that the field containing the templates list is called _templates
. The below query returns all items with a passed-in template:
{
# 3BD4AD928374500C836811A4F049ED22 = ContentBlock template ID
search(where: {name: "_templates", value: "3BD4AD928374500C836811A4F049ED22", operator: EQ}) {
total
results {
id
name
path
hasChildren
}
}
}
More Info
Special field handling
There a handful of standard fields that support a short-hand syntax, allowing you to use a default search operator and not have to pass one in. Here's the list from the SearchService
constructor:
private Dictionary<string, ItemSearchOperator> supportedFields;
public SearchService(IOperationHandlerFactory operationHandlerFactory, IPaginationService paginationService)
{
supportedFields = new Dictionary<string, ItemSearchOperator>();
supportedFields.Add("_name", ItemSearchOperator.EQ);
supportedFields.Add("_language", ItemSearchOperator.EQ);
supportedFields.Add("_path", ItemSearchOperator.CONTAINS);
supportedFields.Add("_templates", ItemSearchOperator.CONTAINS);
supportedFields.Add("_hasLayout", ItemSearchOperator.EQ);
supportedFields.Add("_parent", ItemSearchOperator.EQ);
_operationHandlerFactory = operationHandlerFactory;
_paginationService = paginationService;
}
Therefore, you can simplify the above query by removing the operator: EQ
section, if you wish.
Other fields
You can also use your own fields to search against, like so:
{
# 3BD4AD928374500C836811A4F049ED22 = ContentBlock template ID
search(
where: {
name: "_templates"
value: "3BD4AD928374500C836811A4F049ED22"
AND: { name: "heading", value: "", operator: NEQ }
}
) {
total
results {
id
name
path
hasChildren
fields {
name
value
}
}
}
}
Or, you can search against any other standard field in the Solr index (just make sure you include the operator
property):
{
search(
where: {
name: "_displayname"
value: "content"
operator: CONTAINS
}
) {
total
results {
id
name
path
hasChildren
fields {
name
value
}
}
}
}