advanced-search: Geopoint! type must have a selection of subfields
Closed this issue · 2 comments
Draykee commented
When trying to search the index, I get this following error.
Request:
const request_data = {
"operationName": "AdvancedSearch",
"variables": {
"input": {
"term": "Test",
"groupByProduct": true,
"applyCurations": true,
"logAnalytics": false,
"skip": 0,
"take": 25,
"prefixMode": false
}
},
"query": `query AdvancedSearch($input: SearchInput!) {\n search(input: $input) {
totalItems
searchTimeMs
facetValues {
facetValue {
id
name
facet {
id
name
__typename
}
__typename
}
count
__typename
}
collections {
collection {
id
name
__typename
}
count
__typename
}
items {
...SearchItem
__typename
}
__typename
}
}
fragment SearchItem on SearchResult {
id
score
productId
sku
productName
productVariantName
highlights {
field
snippet
__typename
}
productAsset {
id
preview
focalPoint {
x
y
__typename
}
__typename
}
productVariantAsset {
id
preview
focalPoint {
x
y
__typename
}
__typename
}
customMappings {
/* many things..*/
location //<-- not a primitive tpye
updatedAt
hasShipping
shippingFee
availableChannelIds
availableChannelName
__typename
}
__typename
`
}
Response:
{
"errors": [
{
"message": "Field \"location\" of type \"Geopoint!\" must have a selection of subfields. Did you mean \"location { ... }\"?",
"locations": [
{
"line": 82,
"column": 5
}
],
"extensions": {
"http": {
"status": 400,
"headers": {}
},
"code": "GRAPHQL_VALIDATION_FAILED"
}
}
]
}
Draykee commented
Draykee commented
I believe the fix could look like this:
"Inside the API schema definition"
type CustomMapping {
name: String!
searchable: Boolean!
"Reveal the type via the API"
graphQlType: String!
}
// inside product-index.component.ts
private addCustomMappingsToSearchDocument(/*...*/) {
//...
selectionSet: {
kind: Kind.SELECTION_SET,
selections: customMappings.map(
def =>
({
kind: Kind.FIELD,
name: {
kind: Kind.NAME,
value: def.name,
},
selectionSet: /* if type==Geopoint */
} as FieldNode),
),
}
}