@graphcommerce/algolia-categories 9.1.0-canary.28 → 9.1.0-canary.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/graphql/fragments/AlgoliaCategorySearch.graphql +4 -0
- package/mesh/algoliaHitToMagentoCategory.ts +7 -10
- package/mesh/resolvers.ts +17 -20
- package/package.json +10 -10
- package/plugins/categoriesApplySearchDefaultAlgolia.ts +16 -0
- package/schema/AlgoliaCategorySchema.graphqls +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @graphcommerce/algolia-categories
|
|
2
2
|
|
|
3
|
+
## 9.1.0-canary.31
|
|
4
|
+
|
|
5
|
+
## 9.1.0-canary.30
|
|
6
|
+
|
|
7
|
+
## 9.1.0-canary.29
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- [#2525](https://github.com/graphcommerce-org/graphcommerce/pull/2525) [`f9176ad`](https://github.com/graphcommerce-org/graphcommerce/commit/f9176adf3bf643ac00c865fc173a80056d8b8170) - Search Categories through algolia ([@paales](https://github.com/paales))
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#2525](https://github.com/graphcommerce-org/graphcommerce/pull/2525) [`c9ac114`](https://github.com/graphcommerce-org/graphcommerce/commit/c9ac1142cb92394eb32dc4a6d3944a1707b1b4e2) - Allow returning the algolia index name that is being searched ([@paales](https://github.com/paales))
|
|
16
|
+
|
|
3
17
|
## 9.1.0-canary.28
|
|
4
18
|
|
|
5
19
|
## 9.1.0-canary.27
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { algoliaUrlToUrlKey } from '@graphcommerce/algolia-products
|
|
2
|
-
import type { GetStoreConfigReturn } from '@graphcommerce/algolia-products/mesh/getStoreConfig'
|
|
1
|
+
import { algoliaUrlToUrlKey } from '@graphcommerce/algolia-products'
|
|
3
2
|
import type {
|
|
4
3
|
Algoliahit,
|
|
5
4
|
AlgoliaProductHitAdditionalProperties,
|
|
@@ -39,18 +38,16 @@ export type CategoriesItemsItem = NonNullable<
|
|
|
39
38
|
>['items']
|
|
40
39
|
>[number]
|
|
41
40
|
|
|
42
|
-
function mapBreadcrumbs(algoliaPath) {
|
|
43
|
-
|
|
41
|
+
function mapBreadcrumbs(algoliaPath: string) {
|
|
42
|
+
// Remove the last item from the path, because it's the category itself
|
|
43
|
+
const pathArray = algoliaPath.split(' / ').slice(0, -1)
|
|
44
44
|
return pathArray.map((item) => ({
|
|
45
45
|
category_name: item,
|
|
46
|
-
category_uid: 0,
|
|
46
|
+
category_uid: '0',
|
|
47
47
|
}))
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export function algoliaHitToMagentoCategory(
|
|
51
|
-
hit: Algoliahit,
|
|
52
|
-
storeConfig: GetStoreConfigReturn,
|
|
53
|
-
): CategoriesItemsItem {
|
|
50
|
+
export function algoliaHitToMagentoCategory(hit: Algoliahit): CategoriesItemsItem {
|
|
54
51
|
const { objectID, additionalProperties } = hit
|
|
55
52
|
|
|
56
53
|
if (!assertAdditional(additionalProperties)) return null
|
|
@@ -62,7 +59,7 @@ export function algoliaHitToMagentoCategory(
|
|
|
62
59
|
uid: objectID,
|
|
63
60
|
redirect_code: 0,
|
|
64
61
|
url_key: '',
|
|
65
|
-
url_path: algoliaUrlToUrlKey(additionalProperties.url
|
|
62
|
+
url_path: algoliaUrlToUrlKey(additionalProperties.url),
|
|
66
63
|
breadcrumbs: mapBreadcrumbs(additionalProperties?.path),
|
|
67
64
|
product_count: additionalProperties?.product_count,
|
|
68
65
|
meta_description: additionalProperties?.meta_description,
|
package/mesh/resolvers.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nonNullable } from '@graphcommerce/algolia-products'
|
|
2
2
|
import { type Resolvers } from '@graphcommerce/graphql-mesh'
|
|
3
|
-
import type {
|
|
3
|
+
import type { GraphQLError } from 'graphql'
|
|
4
4
|
import { algoliaHitToMagentoCategory } from './algoliaHitToMagentoCategory'
|
|
5
5
|
import { getCategoryResults } from './getCategoryResults'
|
|
6
|
+
import { getIndexName } from './getIndexName'
|
|
7
|
+
|
|
8
|
+
function isGraphQLError(err: unknown): err is GraphQLError {
|
|
9
|
+
return !!(err as GraphQLError)?.message
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
export const resolvers: Resolvers = {
|
|
8
13
|
Query: {
|
|
@@ -11,29 +16,21 @@ export const resolvers: Resolvers = {
|
|
|
11
16
|
|
|
12
17
|
if (!isAgolia) return context.m2.Query.categories({ root, args, context, info })
|
|
13
18
|
|
|
14
|
-
const
|
|
19
|
+
const searchResults = await getCategoryResults(args, context, info)
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getStoreConfig(context),
|
|
19
|
-
])
|
|
20
|
-
|
|
21
|
-
if (!algoliaResponse?.hits) return context.m2.Query.categories({ root, args, context, info })
|
|
22
|
-
for (const hit of algoliaResponse.hits) {
|
|
23
|
-
if (hit?.objectID) {
|
|
24
|
-
const category = algoliaHitToMagentoCategory(hit, storeConfig)
|
|
25
|
-
items.push(category)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
21
|
+
if (isGraphQLError(searchResults))
|
|
22
|
+
return context.m2.Query.categories({ root, args, context, info })
|
|
28
23
|
|
|
29
24
|
return {
|
|
30
|
-
items,
|
|
25
|
+
items: (searchResults?.hits ?? []).filter(nonNullable).map(algoliaHitToMagentoCategory),
|
|
31
26
|
page_info: {
|
|
32
|
-
current_page:
|
|
33
|
-
page_size:
|
|
34
|
-
total_pages:
|
|
27
|
+
current_page: (searchResults?.page ?? 0) + 1,
|
|
28
|
+
page_size: searchResults?.hitsPerPage,
|
|
29
|
+
total_pages: searchResults?.nbPages,
|
|
35
30
|
},
|
|
36
|
-
total_count:
|
|
31
|
+
total_count: searchResults?.nbHits,
|
|
32
|
+
algolia_queryID: searchResults?.queryID,
|
|
33
|
+
algolia_indexName: getIndexName(context),
|
|
37
34
|
}
|
|
38
35
|
},
|
|
39
36
|
},
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/algolia-categories",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.1.0-canary.
|
|
5
|
+
"version": "9.1.0-canary.31",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"generate": "tsx scripts/generate-spec.mts"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@graphcommerce/algolia-products": "^9.1.0-canary.
|
|
19
|
-
"@graphcommerce/google-datalayer": "^9.1.0-canary.
|
|
20
|
-
"@graphcommerce/graphql": "^9.1.0-canary.
|
|
21
|
-
"@graphcommerce/graphql-mesh": "^9.1.0-canary.
|
|
22
|
-
"@graphcommerce/magento-customer": "^9.1.0-canary.
|
|
23
|
-
"@graphcommerce/magento-product": "^9.1.0-canary.
|
|
24
|
-
"@graphcommerce/magento-search": "^9.1.0-canary.
|
|
25
|
-
"@graphcommerce/next-config": "^9.1.0-canary.
|
|
26
|
-
"@graphcommerce/next-ui": "^9.1.0-canary.
|
|
18
|
+
"@graphcommerce/algolia-products": "^9.1.0-canary.31",
|
|
19
|
+
"@graphcommerce/google-datalayer": "^9.1.0-canary.31",
|
|
20
|
+
"@graphcommerce/graphql": "^9.1.0-canary.31",
|
|
21
|
+
"@graphcommerce/graphql-mesh": "^9.1.0-canary.31",
|
|
22
|
+
"@graphcommerce/magento-customer": "^9.1.0-canary.31",
|
|
23
|
+
"@graphcommerce/magento-product": "^9.1.0-canary.31",
|
|
24
|
+
"@graphcommerce/magento-search": "^9.1.0-canary.31",
|
|
25
|
+
"@graphcommerce/next-config": "^9.1.0-canary.31",
|
|
26
|
+
"@graphcommerce/next-ui": "^9.1.0-canary.31",
|
|
27
27
|
"react": "^18.2.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { categoriesApplySearchDefaults as original } from '@graphcommerce/magento-search'
|
|
2
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
|
|
4
|
+
export const config: PluginConfig = {
|
|
5
|
+
type: 'function',
|
|
6
|
+
module: '@graphcommerce/magento-search',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const categoriesApplySearchDefaults: FunctionPlugin<typeof original> = (
|
|
10
|
+
prev,
|
|
11
|
+
props,
|
|
12
|
+
conf,
|
|
13
|
+
) => {
|
|
14
|
+
const result = prev(props, conf)
|
|
15
|
+
return { ...result, filters: { ...result.filters, engine: { in: ['algolia'] } } }
|
|
16
|
+
}
|