Merge branch 'master' into shopify-i18n

This commit is contained in:
cond0r 2021-05-24 19:59:01 +03:00 committed by GitHub
commit 1e119b79f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 15 deletions

View File

@ -10,11 +10,15 @@ export const handler: SWRHook<Customer | null> = {
query: getCustomerQuery,
},
async fetcher({ options, fetch }) {
const data = await fetch<any | null>({
const customerAccessToken = getCustomerToken()
if (customerAccessToken) {
const data = await fetch({
...options,
variables: { customerAccessToken: getCustomerToken() },
})
return data.customer ?? null
return data.customer
}
return null
},
useHook: ({ useData }) => (input) => {
return useData({

View File

@ -1,5 +1,4 @@
import { getConfig, ShopifyConfig } from '../api'
import fetchAllProducts from '../api/utils/fetch-all-products'
import { ProductEdge } from '../schema'
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
@ -20,21 +19,22 @@ const getAllProductPaths = async (options?: {
config?: ShopifyConfig
preview?: boolean
}): Promise<ReturnType> => {
let { config, variables = { first: 250 } } = options ?? {}
let { config, variables = { first: 100, sortKey: 'BEST_SELLING' } } =
options ?? {}
config = getConfig(config)
const products = await fetchAllProducts({
config,
query: getAllProductsPathsQuery,
const { data } = await config.fetch(getAllProductsPathsQuery, {
variables,
})
return {
products: products?.map(({ node: { handle } }: ProductEdge) => ({
products: data.products?.edges?.map(
({ node: { handle } }: ProductEdge) => ({
node: {
path: `/${handle}`,
},
})),
})
),
}
}

View File

@ -35,6 +35,7 @@ const getAllProducts = async (options: {
}),
}
)
products = [
...products,
...data.products.edges.map(({ node: p }) => normalizeProduct(p)),