mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Aligned with upstream changes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { Page, PageEdge } from '../schema'
|
||||
import { PageEdge } from '../schema'
|
||||
import { getAllPagesQuery } from '../utils/queries'
|
||||
|
||||
type Variables = {
|
||||
@@ -10,6 +10,14 @@ type ReturnType = {
|
||||
pages: Page[]
|
||||
}
|
||||
|
||||
export type Page = {
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
sort_order?: number
|
||||
body: string
|
||||
}
|
||||
|
||||
const getAllPages = async (options?: {
|
||||
variables?: Variables
|
||||
config: ShopifyConfig
|
||||
@@ -21,10 +29,13 @@ const getAllPages = async (options?: {
|
||||
const { data } = await config.fetch(getAllPagesQuery, { variables })
|
||||
const edges = data.pages?.edges
|
||||
|
||||
const pages = edges?.map(({ node }: PageEdge) => ({
|
||||
...node,
|
||||
url: node.handle,
|
||||
}))
|
||||
const pages = edges?.map(
|
||||
({ node: { title: name, handle: url, ...node } }: PageEdge) => ({
|
||||
...node,
|
||||
url,
|
||||
name,
|
||||
})
|
||||
)
|
||||
|
||||
return { pages }
|
||||
}
|
||||
|
@@ -1,15 +1,13 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import getPageQuery from '@framework/utils/queries/get-page-query'
|
||||
import { Page, PageEdge } from '@framework/schema'
|
||||
import getPageQuery from '../utils/queries/get-page-query'
|
||||
import { Page } from './get-all-pages'
|
||||
|
||||
type Variables = {
|
||||
slug: string
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
page: any
|
||||
page: Page
|
||||
}
|
||||
|
||||
const getPage = async (options: {
|
||||
@@ -20,16 +18,17 @@ const getPage = async (options: {
|
||||
let { config, variables } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data }: GraphQLFetcherResult = await config.fetch(getPageQuery, {
|
||||
const { data } = await config.fetch(getPageQuery, {
|
||||
variables,
|
||||
})
|
||||
|
||||
const page: Page = data.pageByHandle
|
||||
const page = data.pageByHandle
|
||||
|
||||
return {
|
||||
page: page
|
||||
? {
|
||||
...page,
|
||||
name: page.title,
|
||||
url: page?.handle,
|
||||
}
|
||||
: null,
|
||||
|
Reference in New Issue
Block a user