mirror of
https://github.com/vercel/commerce.git
synced 2025-05-21 00:46:59 +00:00
24 lines
575 B
TypeScript
24 lines
575 B
TypeScript
import { Category } from '@commerce/types/site'
|
|
import { SaleorConfig } from '../api'
|
|
import { CollectionCountableEdge } from '../schema'
|
|
import * as query from './queries'
|
|
|
|
const getCategories = async (config: SaleorConfig): Promise<Category[]> => {
|
|
const { data } = await config.fetch(query.CollectionMany, {
|
|
variables: {
|
|
first: 100,
|
|
},
|
|
})
|
|
|
|
return (
|
|
data.collections?.edges?.map(({ node: { id, name, slug } }: CollectionCountableEdge) => ({
|
|
id,
|
|
name,
|
|
slug,
|
|
path: `/${slug}`,
|
|
})) ?? []
|
|
)
|
|
}
|
|
|
|
export default getCategories
|