mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 13:11:23 +00:00
Changed to query page by id
This commit is contained in:
parent
1c7ac7d795
commit
590bff576c
@ -8,7 +8,6 @@ import {
|
||||
} from '../const'
|
||||
|
||||
if (!API_URL) {
|
||||
console.log(process.env)
|
||||
throw new Error(
|
||||
`The environment variable NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN is missing and it's required to access your store`
|
||||
)
|
||||
|
@ -25,12 +25,14 @@ const getAllPages = async (options?: {
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
const { locale = 'en-US' } = config
|
||||
|
||||
const { data } = await config.fetch(getAllPagesQuery, { variables })
|
||||
|
||||
const pages = data.pages?.edges?.map(
|
||||
({ node: { title: name, handle, ...node } }: PageEdge) => ({
|
||||
...node,
|
||||
url: `/${handle}`,
|
||||
url: `/${locale}/${handle}`,
|
||||
name,
|
||||
})
|
||||
)
|
||||
|
@ -2,34 +2,33 @@ import { getConfig, ShopifyConfig } from '../api'
|
||||
import getPageQuery from '../utils/queries/get-page-query'
|
||||
import { Page } from './get-all-pages'
|
||||
|
||||
type Variables = {
|
||||
slug: string
|
||||
type PageVariables = {
|
||||
id: string
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
page: Page
|
||||
}
|
||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||
|
||||
const getPage = async (options: {
|
||||
variables: Variables
|
||||
variables: PageVariables
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
}): Promise<GetPageResult> => {
|
||||
let { config, variables } = options ?? {}
|
||||
|
||||
config = getConfig(config)
|
||||
const { locale = 'en-US' } = config
|
||||
|
||||
const { data } = await config.fetch(getPageQuery, {
|
||||
variables,
|
||||
})
|
||||
|
||||
const { pageByHandle: page } = data
|
||||
const page = data.node
|
||||
|
||||
return {
|
||||
page: page
|
||||
? {
|
||||
...page,
|
||||
name: page.title,
|
||||
url: page?.handle,
|
||||
url: `/${locale}/${page.handle}`,
|
||||
}
|
||||
: null,
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ export type SearchProductsData = {
|
||||
products: Product[]
|
||||
found: boolean
|
||||
}
|
||||
|
||||
export const handler: SWRHook<
|
||||
SearchProductsData,
|
||||
SearchProductsInput,
|
||||
|
@ -1,12 +1,13 @@
|
||||
export const getPageQuery = /* GraphQL */ `
|
||||
query getPageBySlug($slug: String!) {
|
||||
pageByHandle(handle: $slug) {
|
||||
query($id: ID!) {
|
||||
node(id: $id) {
|
||||
id
|
||||
title
|
||||
handle
|
||||
body
|
||||
bodySummary
|
||||
url
|
||||
... on Page {
|
||||
title
|
||||
handle
|
||||
body
|
||||
bodySummary
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
Loading…
x
Reference in New Issue
Block a user