4
0
forked from crowetic/commerce
commerce/framework/shopify/common/get-site-info.ts
2021-02-04 13:23:44 +02:00

32 lines
758 B
TypeScript

import { CollectionEdge } from '@framework/schema'
import { getConfig, ShopifyConfig } from '../api'
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
const getSiteInfo = async (options?: {
variables?: any
config: ShopifyConfig
preview?: boolean
}) => {
let { config, variables = { first: 250 } } = options ?? {}
config = getConfig(config)
const { data } = await config.fetch(getAllCollectionsQuery, { variables })
const edges = data.collections?.edges ?? []
const categories = edges.map(
({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
entityId,
name,
path: `/${handle}`,
})
)
return {
categories,
brands: [],
}
}
export default getSiteInfo