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