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']> {
|
} = {}): Promise<T['data']> {
|
||||||
const { fetch, locale } = commerce.getConfig(config)
|
const { fetch, locale } = commerce.getConfig(config)
|
||||||
|
|
||||||
const { data } = await fetch<
|
try {
|
||||||
GetAllProductsQuery,
|
const { data } = await fetch<
|
||||||
GetAllProductsQueryVariables
|
GetAllProductsQuery,
|
||||||
>(
|
GetAllProductsQueryVariables
|
||||||
query,
|
>(
|
||||||
{ variables },
|
query,
|
||||||
{
|
{ variables },
|
||||||
...(locale && {
|
{
|
||||||
headers: {
|
...(locale && {
|
||||||
'Accept-Language': locale,
|
headers: {
|
||||||
},
|
'Accept-Language': locale,
|
||||||
}),
|
},
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
console.log({ data })
|
||||||
|
return {
|
||||||
|
products: [],
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
// return {
|
||||||
products: data.products.edges.map(({ node }) =>
|
// products: data?.products?.edges
|
||||||
normalizeProduct(node as WooCommerceProduct)
|
// ? data.products.edges.map(({ node }) =>
|
||||||
),
|
// normalizeProduct(node as WooCommerceProduct)
|
||||||
|
// )
|
||||||
|
// : [],
|
||||||
|
// }
|
||||||
|
} catch (e) {
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,22 @@ const fetchGraphqlApi: GraphQLFetcher = async (
|
|||||||
fetchOptions
|
fetchOptions
|
||||||
) => {
|
) => {
|
||||||
try {
|
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, {
|
const res = await fetch(API_URL, {
|
||||||
...fetchOptions,
|
...fetchOptions,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -26,18 +42,22 @@ const fetchGraphqlApi: GraphQLFetcher = async (
|
|||||||
const { data, errors, status } = await res.json()
|
const { data, errors, status } = await res.json()
|
||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
throw getError(errors, status)
|
console.log({ errors: errors[0].extensions })
|
||||||
|
console.log(getError(errors, status))
|
||||||
}
|
}
|
||||||
|
|
||||||
return { data, res }
|
return { data, res }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw getError(
|
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.`,
|
[
|
||||||
},
|
{
|
||||||
],
|
message: `${err} \n Most likely related to an unexpected output. e.g the store might be protected with password or not available.`,
|
||||||
500
|
},
|
||||||
|
],
|
||||||
|
500
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { FetcherError } from '@commerce/utils/errors'
|
import { FetcherError } from '@commerce/utils/errors'
|
||||||
|
|
||||||
export function getError(errors: any[] | null, status: number) {
|
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 })
|
return new FetcherError({ errors, status })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
import commerce from '@lib/api/commerce'
|
import commerce from '@lib/api/commerce'
|
||||||
import { Layout } from '@components/common'
|
import { Layout } from '@components/common'
|
||||||
import { ProductCard } from '@components/product'
|
import { ProductCard } from '@components/product'
|
||||||
@@ -11,26 +12,35 @@ export async function getStaticProps({
|
|||||||
locales,
|
locales,
|
||||||
}: GetStaticPropsContext) {
|
}: GetStaticPropsContext) {
|
||||||
const config = { locale, locales }
|
const config = { locale, locales }
|
||||||
const productsPromise = commerce.getAllProducts({
|
const productsPromise = await commerce.getAllProducts({
|
||||||
variables: { first: 6 },
|
variables: { first: 6 },
|
||||||
config,
|
config,
|
||||||
preview,
|
preview,
|
||||||
// Saleor provider only
|
// // Saleor provider only
|
||||||
...({ featured: true } as any),
|
// ...({ 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 {
|
return {
|
||||||
// props: {
|
props: {
|
||||||
// products,
|
products: [],
|
||||||
// categories,
|
// categories,
|
||||||
// brands,
|
// brands,
|
||||||
// pages,
|
// pages,
|
||||||
// },
|
},
|
||||||
revalidate: 60,
|
revalidate: 60,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ export async function getStaticProps({
|
|||||||
preview,
|
preview,
|
||||||
})
|
})
|
||||||
|
|
||||||
const allProductsPromise = commerce.getAllProducts({
|
const allProductsPromise = await commerce.getAllProducts({
|
||||||
variables: { first: 4 },
|
variables: { first: 4 },
|
||||||
config,
|
config,
|
||||||
preview,
|
preview,
|
||||||
|
Reference in New Issue
Block a user