mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 15:55:54 +00:00
36 lines
808 B
TypeScript
36 lines
808 B
TypeScript
import type { OperationContext } from '@commerce/api/operations'
|
|
import { Category } from '@commerce/types/site'
|
|
import type { SaleorConfig, Provider } from '..'
|
|
|
|
import { getCategories, getVendors } from '../../utils'
|
|
|
|
interface GetSiteInfoResult {
|
|
categories: Category[]
|
|
brands: any[]
|
|
}
|
|
|
|
export default function getSiteInfoOperation({ commerce }: OperationContext<Provider>) {
|
|
async function getSiteInfo({
|
|
query,
|
|
config,
|
|
variables,
|
|
}: {
|
|
query?: string
|
|
config?: Partial<SaleorConfig>
|
|
preview?: boolean
|
|
variables?: any
|
|
} = {}): Promise<GetSiteInfoResult> {
|
|
const cfg = commerce.getConfig(config)
|
|
|
|
const categories = await getCategories(cfg)
|
|
const brands = await getVendors(cfg)
|
|
|
|
return {
|
|
categories,
|
|
brands,
|
|
}
|
|
}
|
|
|
|
return getSiteInfo
|
|
}
|