mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Initial work, copied from the Shopify provider
This commit is contained in:
42
framework/saleor/common/get-all-pages.ts
Normal file
42
framework/saleor/common/get-all-pages.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { getConfig, SaleorConfig } from '../api'
|
||||
import { PageEdge } from '../schema'
|
||||
import { getAllPagesQuery } from '../utils/queries'
|
||||
|
||||
type Variables = {
|
||||
first?: number
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
pages: Page[]
|
||||
}
|
||||
|
||||
export type Page = {
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
sort_order?: number
|
||||
body: string
|
||||
}
|
||||
|
||||
const getAllPages = async (options?: {
|
||||
variables?: Variables
|
||||
config: SaleorConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
const { locale } = config
|
||||
const { data } = await config.fetch(getAllPagesQuery, { variables })
|
||||
|
||||
const pages = data.pages?.edges?.map(
|
||||
({ node: { title: name, handle, ...node } }: PageEdge) => ({
|
||||
...node,
|
||||
url: `/${locale}/${handle}`,
|
||||
name,
|
||||
})
|
||||
)
|
||||
|
||||
return { pages }
|
||||
}
|
||||
|
||||
export default getAllPages
|
Reference in New Issue
Block a user