mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
save before rebase
This commit is contained in:
12
.vscode/launch.json
vendored
Normal file
12
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"name": "Attach to application",
|
||||
"skipFiles": ["<node_internals>/**"],
|
||||
"port": 9229
|
||||
}
|
||||
]
|
||||
}
|
@@ -41,25 +41,35 @@ export default function getAllProductsOperation({
|
||||
} = {}): Promise<T['data']> {
|
||||
const { fetch, locale } = commerce.getConfig(config)
|
||||
|
||||
const { data } = await fetch<
|
||||
GetAllProductsQuery,
|
||||
GetAllProductsQueryVariables
|
||||
>(
|
||||
query,
|
||||
{ variables },
|
||||
{
|
||||
...(locale && {
|
||||
headers: {
|
||||
'Accept-Language': locale,
|
||||
},
|
||||
}),
|
||||
try {
|
||||
const { data } = await fetch<
|
||||
GetAllProductsQuery,
|
||||
GetAllProductsQueryVariables
|
||||
>(
|
||||
query,
|
||||
{ variables },
|
||||
{
|
||||
...(locale && {
|
||||
headers: {
|
||||
'Accept-Language': locale,
|
||||
},
|
||||
}),
|
||||
}
|
||||
)
|
||||
console.log({ data })
|
||||
return {
|
||||
products: [],
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
products: data.products.edges.map(({ node }) =>
|
||||
normalizeProduct(node as WooCommerceProduct)
|
||||
),
|
||||
// return {
|
||||
// products: data?.products?.edges
|
||||
// ? data.products.edges.map(({ node }) =>
|
||||
// normalizeProduct(node as WooCommerceProduct)
|
||||
// )
|
||||
// : [],
|
||||
// }
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,22 @@ const fetchGraphqlApi: GraphQLFetcher = async (
|
||||
fetchOptions
|
||||
) => {
|
||||
try {
|
||||
console.log({
|
||||
resss: {
|
||||
API_URL,
|
||||
...fetchOptions,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...fetchOptions?.headers,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
variables,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
const res = await fetch(API_URL, {
|
||||
...fetchOptions,
|
||||
method: 'POST',
|
||||
@@ -26,18 +42,22 @@ const fetchGraphqlApi: GraphQLFetcher = async (
|
||||
const { data, errors, status } = await res.json()
|
||||
|
||||
if (errors) {
|
||||
throw getError(errors, status)
|
||||
console.log({ errors: errors[0].extensions })
|
||||
console.log(getError(errors, status))
|
||||
}
|
||||
|
||||
return { data, res }
|
||||
} catch (err) {
|
||||
throw getError(
|
||||
[
|
||||
{
|
||||
message: `${err} \n Most likely related to an unexpected output. e.g the store might be protected with password or not available.`,
|
||||
},
|
||||
],
|
||||
500
|
||||
console.log({ err })
|
||||
console.log(
|
||||
getError(
|
||||
[
|
||||
{
|
||||
message: `${err} \n Most likely related to an unexpected output. e.g the store might be protected with password or not available.`,
|
||||
},
|
||||
],
|
||||
500
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
|
||||
export function getError(errors: any[] | null, status: number) {
|
||||
errors = errors ?? [{ message: 'Failed to fetch Shopify API' }]
|
||||
errors = errors ?? [{ message: 'Failed to fetch WooCommerce API' }]
|
||||
return new FetcherError({ errors, status })
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import { useEffect } from 'react'
|
||||
import commerce from '@lib/api/commerce'
|
||||
import { Layout } from '@components/common'
|
||||
import { ProductCard } from '@components/product'
|
||||
@@ -11,26 +12,35 @@ export async function getStaticProps({
|
||||
locales,
|
||||
}: GetStaticPropsContext) {
|
||||
const config = { locale, locales }
|
||||
const productsPromise = commerce.getAllProducts({
|
||||
const productsPromise = await commerce.getAllProducts({
|
||||
variables: { first: 6 },
|
||||
config,
|
||||
preview,
|
||||
// Saleor provider only
|
||||
...({ featured: true } as any),
|
||||
// // Saleor provider only
|
||||
// ...({ featured: true } as any),
|
||||
})
|
||||
// // const pagesPromise = commerce.getAllPages({ config, preview })
|
||||
// // const siteInfoPromise = commerce.getSiteInfo({ config, preview })
|
||||
// // const { products } = await productsPromise
|
||||
// // const { pages } = await pagesPromise
|
||||
// // const { categories, brands } = await siteInfoPromise
|
||||
console.log({
|
||||
query: {
|
||||
variables: { first: 6 },
|
||||
config,
|
||||
preview,
|
||||
// // Saleor provider only
|
||||
// ...({ featured: true } as any),
|
||||
},
|
||||
productsPromise,
|
||||
})
|
||||
// const pagesPromise = commerce.getAllPages({ config, preview })
|
||||
// const siteInfoPromise = commerce.getSiteInfo({ config, preview })
|
||||
// const { products } = await productsPromise
|
||||
// const { pages } = await pagesPromise
|
||||
// const { categories, brands } = await siteInfoPromise
|
||||
|
||||
return {
|
||||
// props: {
|
||||
// products,
|
||||
// categories,
|
||||
// brands,
|
||||
// pages,
|
||||
// },
|
||||
props: {
|
||||
products: [],
|
||||
// categories,
|
||||
// brands,
|
||||
// pages,
|
||||
},
|
||||
revalidate: 60,
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ export async function getStaticProps({
|
||||
preview,
|
||||
})
|
||||
|
||||
const allProductsPromise = commerce.getAllProducts({
|
||||
const allProductsPromise = await commerce.getAllProducts({
|
||||
variables: { first: 4 },
|
||||
config,
|
||||
preview,
|
||||
|
Reference in New Issue
Block a user