Integrate your own data sources
Customise Hits via a Resolver​
- Add to the schema and update the type that has been configured as the
hitTypeName
. Normally this would beResultHit
. Below is an example of adding an additional field in Hit in the schema
type ResultHit implements SKHit {
id: ID!
fields: ResultFields
exampleCustomField: String // example field addition
}
Then provide a resolver for the field. See ResultsResolver for what can be provided.
resolvers: withSearchkitResolvers({
ResultHit: {
exampleCustomField: ({
id, // id contents
rawHit // the raw ES hit contents
}) => `Example Return Value for ${id}`
}
}),
then with a GQL query like below
query {
results {
hits {
items {
... on ResultHit {
id
exampleCustomField
}
}
}
}
}
will call the exampleCustomField resolver for each hit item. The parent object (passed as an argument) contains the HitFields values. The return value is what will be provided in the response.
{
"data": {
"results": {
"hits": {
"items": [
{
"id": "tt0111161",
"exampleCustomField": "Example Return Value for tt0111161"
}
]
}
}
}
}