mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Updated getPage usage
This commit is contained in:
parent
f4e7cb51fa
commit
74a93b4900
@ -9,10 +9,10 @@ import { BigcommerceConfig, Provider } from '..'
|
||||
export default function getAllPagesOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function getAllPages(opts?: {
|
||||
async function getAllPages<T extends GetAllPagesOperation>(opts?: {
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<GetAllPagesOperation['data']>
|
||||
}): Promise<T['data']>
|
||||
|
||||
async function getAllPages<T extends GetAllPagesOperation>(
|
||||
opts: {
|
||||
@ -21,14 +21,14 @@ export default function getAllPagesOperation({
|
||||
} & OperationOptions
|
||||
): Promise<T['data']>
|
||||
|
||||
async function getAllPages({
|
||||
async function getAllPages<T extends GetAllPagesOperation>({
|
||||
config,
|
||||
preview,
|
||||
}: {
|
||||
url?: string
|
||||
config?: BigcommerceConfig
|
||||
preview?: boolean
|
||||
} = {}): Promise<GetAllPagesOperation['data']> {
|
||||
} = {}): Promise<T['data']> {
|
||||
config = commerce.getConfig(config)
|
||||
// RecursivePartial forces the method to check for every prop in the data, which is
|
||||
// required in case there's a custom `url`
|
||||
|
@ -20,11 +20,11 @@ export const loginMutation = /* GraphQL */ `
|
||||
export default function loginOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
async function login(opts: {
|
||||
variables: LoginOperation['variables']
|
||||
async function login<T extends LoginOperation>(opts: {
|
||||
variables: T['variables']
|
||||
config?: BigcommerceConfig
|
||||
res: ServerResponse
|
||||
}): Promise<LoginOperation['data']>
|
||||
}): Promise<T['data']>
|
||||
|
||||
async function login<T extends LoginOperation>(
|
||||
opts: {
|
||||
@ -34,17 +34,17 @@ export default function loginOperation({
|
||||
} & OperationOptions
|
||||
): Promise<T['data']>
|
||||
|
||||
async function login({
|
||||
async function login<T extends LoginOperation>({
|
||||
query = loginMutation,
|
||||
variables,
|
||||
res: response,
|
||||
config,
|
||||
}: {
|
||||
query?: string
|
||||
variables: LoginOperation['variables']
|
||||
variables: T['variables']
|
||||
res: ServerResponse
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<LoginOperation['data']> {
|
||||
}): Promise<T['data']> {
|
||||
config = commerce.getConfig(config)
|
||||
|
||||
const { data, res } = await config.fetch<RecursivePartial<LoginMutation>>(
|
||||
|
@ -3,13 +3,12 @@ import type {
|
||||
GetStaticPropsContext,
|
||||
InferGetStaticPropsType,
|
||||
} from 'next'
|
||||
import commerce from '@lib/api/commerce'
|
||||
import { Text } from '@components/ui'
|
||||
import { Layout } from '@components/common'
|
||||
import commerce from '@lib/api/commerce'
|
||||
import getSlug from '@lib/get-slug'
|
||||
import { missingLocaleInPages } from '@lib/usage-warns'
|
||||
import { getConfig } from '@framework/api'
|
||||
import getPage from '@framework/api/operations/get-page'
|
||||
import { defaultPageProps } from '@lib/defaults'
|
||||
|
||||
export async function getStaticProps({
|
||||
@ -26,7 +25,11 @@ export async function getStaticProps({
|
||||
const data =
|
||||
pageItem &&
|
||||
// TODO: Shopify - Fix this type
|
||||
(await getPage({ variables: { id: pageItem.id! } as any, config, preview }))
|
||||
(await commerce.getPage({
|
||||
variables: { id: pageItem.id! } as any,
|
||||
config,
|
||||
preview,
|
||||
}))
|
||||
const page = data?.page
|
||||
|
||||
if (!page) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user