Skip to main content

GQL Schema Queries Cheatsheet

Try these examples on the Demo GraphQL Playground

Simple Hits

query {
results {
hits {
items {
... on ResultHit {
id
fields {
## Add your fields via HitFields type
title
}
}
}
}
}
}

Hit Querying

query {
results(query: "heat") {
hits {
items {
... on ResultHit {
id
fields {
title
}
}
}
}
}
}

Hit Filtering

query {
results(
filters: [
{identifier: "type", value: "Movie"}
{identifier: "rangeExample", min: 0, max: 100}
{
identifier: "dateExample"
dateMin: "2020-12-01T00:00:00.000Z"
dateMax: "2020-12-11T00:00:00.000Z"
}
]
) {
hits {
items {
id
}
}
}
}

Facets

Facets are configured together on the Searchkit Config within the facets array. Each facet can support a range of experiences from a simple list to date filtering

When configured, a GraphQL query using the facets node like below will bring back all the facet options for the result set. To apply a facet filter, you can specify the filter in the results arguments, shown below.

{
results(filters: [{identifier: "type", value: "movie"}]) {
facets {
identifier
label
type
display
entries {
label
count
}
}
}
}

The resolver also supports returning facet options for one particular facet via facet node.

{
results(query: "heat") {
facet(identifier: "type") {
identifier
label
type ## facet class type
display ## Used by client on how to display the facet. Can be configured in Facet configuration
entries {
label
count
}
}
}
}

Single Facet

Used for facet interactions such as for search or for when displaying more facet options.

query {
results {
facet(
identifier: "actors"
query: "a" ## query prefix to filter entries
size: 20 ## size options on facet
) {
identifier
label
type
display
entries {
label
count
}
}
}
}

Pagination

query {
results {
hits(
page: {from: 100, size: 100} ## used to control page
) {
items {
id
}
page {
## used for pagination display
total
totalPages
pageNumber
from
size
}
}
}
}

Sorting Results

query {
results {
summary {
sortOptions {
## all available sort options
id
label
}
}
hits(
sortBy: "<id>" ## Wish to sort by, the sort id
) {
sortedBy ## the selected sort, the sort id
}
}
}

Example of sorting

{
results(query: "bla") {
hits(sortBy: "relevance") {
sortedBy
items {
... on ResultHit {
id
fields {
writers
actors
}
}
}
}
}
}

Filter Summary

query {
results {
summary {
query ## the query value
appliedFilters {
## array of filters applied to search
id
identifier
display
label
... on DateRangeSelectedFilter {
dateMin
dateMax
}

... on NumericRangeSelectedFilter {
min
max
}

... on ValueSelectedFilter {
value
}
}
}
hits(page: {from: 100, size: 0}) {
items {
id
}
}
}
}

Selected Date Filter Example

{
results(
filters: [
{identifier: "released", dateMin: "10/12/2020", dateMax: "10/12/2021"}
]
) {
hits {
items {
id
}
}
}
}

Selected Numeric Range Filter Example

{
results(filters: [{identifier: "metascore", min: 0, max: 100}]) {
hits {
items {
id
}
}
}
}

RefinementSelectFacet Filter & Display Example

{
results(filters: [{identifier: "type", value: "movie"}]) {
summary {
appliedFilters {
identifier
id
label
display
... on ValueSelectedFilter {
value
}
}
}
hits {
items {
id
}
}
}
}

Query Options Usage

{
results(query: "heat", queryOptions: {fields: ["title^2", "description^1"]}) {
hits {
items {
id
}
}
}
}

Geo location filtering

Able to filter the results by a geo location with GeoLocationFilter

{
result(
filters: [
{
identifier: "location"
geoBoundingBox: {
topLeft: {lat: 70.73, lon: -95.1}
bottomRight: {lat: 10.01, lon: -65.12}
}
}
]
) {
hits {
items {
id
... on ParkResultHit {
fields {
title
location
}
}
}
}
}
}

HierarchicalMenuFacet GraphQL query

  results(query: "test", filters: [
{ identifier: 'categories', value: "Clothing" }
]) {
summary {
total
appliedFilters {
id
identifier
label
display
... on ValueSelectedFilter {
value
}
}
}
facets {
identifier
label
facets {
identifier
type
label
display
entries {
label
count
entries {
label
count
entries {
label
count
}
}
}
}
}
}
}