mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Merge branch 'master' of github.com:vercel/commerce into outgrow-reaction-commerce-provider
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
50
framework/saleor/api/operations/get-page.ts
Normal file
50
framework/saleor/api/operations/get-page.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { Provider, SaleorConfig } from '..'
|
||||
import { QueryPageArgs } from '../../schema'
|
||||
|
||||
import * as Query from '../../utils/queries'
|
||||
|
||||
export type Page = any
|
||||
|
||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||
|
||||
export default function getPageOperation({ commerce }: OperationContext<Provider>) {
|
||||
async function getPage({
|
||||
query = Query.PageOne,
|
||||
variables,
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables: QueryPageArgs
|
||||
config?: Partial<SaleorConfig>
|
||||
preview?: boolean
|
||||
}): Promise<GetPageResult> {
|
||||
const { fetch, locale = 'en-US' } = commerce.getConfig(config)
|
||||
|
||||
const {
|
||||
data: { page },
|
||||
} = await fetch(
|
||||
query,
|
||||
{ variables },
|
||||
{
|
||||
...(locale && {
|
||||
headers: {
|
||||
'Accept-Language': locale,
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
page: page
|
||||
? {
|
||||
...page,
|
||||
name: page.title,
|
||||
url: `/${locale}/${page.slug}`,
|
||||
}
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
return getPage
|
||||
}
|
Reference in New Issue
Block a user