Divide fetcher with rest and graphql

This commit is contained in:
goncy
2021-08-25 19:51:15 -03:00
parent d4adfd079f
commit 5d76337f9e
16 changed files with 69 additions and 94 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +0,0 @@
export default function getCustomerWishlistOperation() {
function getCustomerWishlist(): any {
return { wishlist: {} }
}
return getCustomerWishlist
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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'