Initial work, copied from the Shopify provider

This commit is contained in:
Patryk Zawadzki
2021-04-14 14:09:40 +02:00
committed by Zaiste
parent 685fb932db
commit ffe5a1c20e
79 changed files with 16981 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
import { CollectionEdge } from '../schema'
import { getConfig, SaleorConfig } from '../api'
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
const getAllCollections = async (options?: {
variables?: any
config: SaleorConfig
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,
}
}
export default getAllCollections