Skip to content

Commit 0d62fff

Browse files
Erik MarrErik Marr
authored andcommitted
Adding new section about how to handle categoryPath error
1 parent 3899389 commit 0d62fff

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

src/pages/graphql/schema/live-search/queries/product-search.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,18 @@ filter:[
386386

387387
##### Error handling for categoryPath
388388

389-
When an empty or invalid `categoryPath` is detected with position sorting, the following warning is returned:
389+
When sorting by category `position` with an empty or invalid `categoryPath`, the Search Service gracefully handles the request to prevent `FAILED_PRECONDITION` errors. This scenario commonly occurs when attempting to sort by position at the root category level, where category paths are not standardized across store views.
390+
391+
**Behavior when empty or invalid categoryPath is detected with position sorting:**
392+
393+
- Category position sort is ignored
394+
- System falls back to relevance-based sorting
395+
- Products are returned successfully
396+
- A structured GraphQL warning is included in the response
397+
398+
**Warning message:**
399+
400+
The following warning is returned in the `errors` array alongside the product data:
390401

391402
```json
392403
{
@@ -404,26 +415,41 @@ When an empty or invalid `categoryPath` is detected with position sorting, the f
404415
}
405416
```
406417

407-
Despite the warning, the query returns product data successfully in the `data` object, sorted by relevance.
418+
<InlineAlert variant="info" slots="text"/>
419+
420+
Despite the warning, the query executes successfully and returns product data in the `data` object, sorted by relevance instead of position.
408421

409-
**Example**
422+
**Example query that triggers the warning:**
410423

411424
```graphql
412-
filter: [
413-
{
414-
attribute: "categoryPath",
415-
eq: null
416-
}
417-
]
418-
sort: [
419-
{
420-
attribute: "position",
421-
direction: "ASC"
425+
{
426+
productSearch(
427+
phrase: "pants"
428+
page_size: 8
429+
filter: [
430+
{
431+
attribute: "categoryPath",
432+
eq: null
433+
}
434+
]
435+
sort: [
436+
{
437+
attribute: "position",
438+
direction: ASC
439+
}
440+
]
441+
) {
442+
items {
443+
productView {
444+
name
445+
sku
446+
}
447+
}
422448
}
423-
]
449+
}
424450
```
425451

426-
This configuration triggers the warning and applies relevance sorting instead of position sorting.
452+
In this example, attempting to sort by `position` with a null `categoryPath` triggers the warning. The system returns products sorted by relevance with the warning message included in the response.
427453

428454
#### categories
429455

0 commit comments

Comments
 (0)