Loan Laux 23e0d57cf5
Move API to new Node architecture
Signed-off-by: Loan Laux <loan@outgrow.io>
2021-07-06 15:43:38 +03:00

36 lines
735 B
TypeScript

import { ReactionCommerceConfig } from '../api'
import { CollectionEdge, TagEdge } from '../schema'
import getTagsQuery from './queries/get-all-collections-query'
export type Category = {
entityId: string
name: string
path: string
}
const getCategories = async (
config: ReactionCommerceConfig
): Promise<Tag[]> => {
const { data } = await config.fetch(getTagsQuery, {
variables: {
first: 250,
shopId: config.shopId,
},
})
return (
data.tags?.edges?.map(
({
node: { _id: entityId, displayTitle: name, slug: handle },
}: TagEdge) => ({
entityId,
name,
path: `/${handle}`,
slug: handle,
})
) ?? []
)
}
export default getCategories