mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
Divide fetcher with rest and graphql
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
export type Page = { url: string }
|
||||
export type GetAllPagesResult = { pages: Page[] }
|
||||
import type { OrdercloudConfig } from '../index'
|
||||
|
||||
export default function getAllPagesOperation() {
|
||||
function getAllPages({
|
||||
config,
|
||||
preview,
|
||||
}: {
|
||||
url?: string
|
||||
config?: Partial<OrdercloudConfig>
|
||||
preview?: boolean
|
||||
}): Promise<GetAllPagesResult> {
|
||||
return Promise.resolve({
|
||||
pages: [],
|
||||
})
|
||||
}
|
||||
return getAllPages
|
||||
}
|
@@ -2,7 +2,7 @@ import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { GetAllProductPathsOperation } from '@commerce/types/product'
|
||||
|
||||
import type { RawProduct } from '../../types/product'
|
||||
import type { OrdercloudConfig, Provider } from '../index'
|
||||
import type { OrdercloudConfig, Provider } from '../'
|
||||
|
||||
export type GetAllProductPathsResult = {
|
||||
products: Array<{ path: string }>
|
||||
@@ -17,13 +17,12 @@ export default function getAllProductPathsOperation({
|
||||
config?: Partial<OrdercloudConfig>
|
||||
} = {}): Promise<T['data']> {
|
||||
// Get fetch from the config
|
||||
const { fetch } = commerce.getConfig(config)
|
||||
const { storeRestFetch } = commerce.getConfig(config)
|
||||
|
||||
// Get all products
|
||||
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
||||
'GET',
|
||||
'/me/products'
|
||||
).then((response) => response.Items)
|
||||
const rawProducts: RawProduct[] = await storeRestFetch<{
|
||||
Items: RawProduct[]
|
||||
}>('GET', '/me/products').then((response) => response.Items)
|
||||
|
||||
return {
|
||||
// Match a path for every product retrieved
|
||||
|
@@ -18,13 +18,12 @@ export default function getAllProductsOperation({
|
||||
preview?: boolean
|
||||
} = {}): Promise<T['data']> {
|
||||
// Get fetch from the config
|
||||
const { fetch } = commerce.getConfig(config)
|
||||
const { storeRestFetch } = commerce.getConfig(config)
|
||||
|
||||
// Get all products
|
||||
const rawProducts: RawProduct[] = await fetch<{ Items: RawProduct[] }>(
|
||||
'GET',
|
||||
'/me/products'
|
||||
).then((response) => response.Items)
|
||||
const rawProducts: RawProduct[] = await storeRestFetch<{
|
||||
Items: RawProduct[]
|
||||
}>('GET', '/me/products').then((response) => response.Items)
|
||||
|
||||
return {
|
||||
// Normalize products to commerce schema
|
||||
|
@@ -1,6 +0,0 @@
|
||||
export default function getCustomerWishlistOperation() {
|
||||
function getCustomerWishlist(): any {
|
||||
return { wishlist: {} }
|
||||
}
|
||||
return getCustomerWishlist
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
export type Page = any
|
||||
export type GetPageResult = { page?: Page }
|
||||
|
||||
export type PageVariables = {
|
||||
id: number
|
||||
}
|
||||
|
||||
export default function getPageOperation() {
|
||||
function getPage(): Promise<GetPageResult> {
|
||||
return Promise.resolve({})
|
||||
}
|
||||
return getPage
|
||||
}
|
@@ -19,22 +19,22 @@ export default function getProductOperation({
|
||||
preview?: boolean
|
||||
} = {}): Promise<T['data']> {
|
||||
// Get fetch from the config
|
||||
const { fetch } = commerce.getConfig(config)
|
||||
const { storeRestFetch } = commerce.getConfig(config)
|
||||
|
||||
// Get a single product
|
||||
const productPromise = fetch<RawProduct>(
|
||||
const productPromise = storeRestFetch<RawProduct>(
|
||||
'GET',
|
||||
`/me/products/${variables?.slug}`
|
||||
)
|
||||
|
||||
// Get product specs
|
||||
const specsPromise = fetch<{ Items: RawSpec[] }>(
|
||||
const specsPromise = storeRestFetch<{ Items: RawSpec[] }>(
|
||||
'GET',
|
||||
`/me/products/${variables?.slug}/specs`
|
||||
).then((res) => res.Items)
|
||||
|
||||
// Get product variants
|
||||
const variantsPromise = fetch<{ Items: RawVariant[] }>(
|
||||
const variantsPromise = storeRestFetch<{ Items: RawVariant[] }>(
|
||||
'GET',
|
||||
`/me/products/${variables?.slug}/variants`
|
||||
).then((res) => res.Items)
|
||||
|
@@ -23,13 +23,12 @@ export default function getSiteInfoOperation({
|
||||
preview?: boolean
|
||||
} = {}): Promise<T['data']> {
|
||||
// Get fetch from the config
|
||||
const { fetch } = commerce.getConfig(config)
|
||||
const { storeRestFetch } = commerce.getConfig(config)
|
||||
|
||||
// Get list of categories
|
||||
const rawCategories: RawCategory[] = await fetch<{ Items: RawCategory[] }>(
|
||||
'GET',
|
||||
`/me/categories`
|
||||
).then((response) => response.Items)
|
||||
const rawCategories: RawCategory[] = await storeRestFetch<{
|
||||
Items: RawCategory[]
|
||||
}>('GET', `/me/categories`).then((response) => response.Items)
|
||||
|
||||
return {
|
||||
// Normalize categories
|
||||
|
@@ -1,6 +1,4 @@
|
||||
export { default as getPage } from './get-page'
|
||||
export { default as getSiteInfo } from './get-site-info'
|
||||
export { default as getAllPages } from './get-all-pages'
|
||||
export { default as getProduct } from './get-product'
|
||||
export { default as getAllProducts } from './get-all-products'
|
||||
export { default as getAllProductPaths } from './get-all-product-paths'
|
||||
|
Reference in New Issue
Block a user