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