forked from crowetic/commerce
Updated types
This commit is contained in:
parent
2f35358942
commit
d095ac9f70
@ -16,17 +16,22 @@ export const getAllProductPathsQuery = /* GraphQL */ `
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export interface GetAllProductPathsResult<T> {
|
export type ProductPaths = NonNullable<
|
||||||
products: T extends GetAllProductPathsQuery
|
GetAllProductPathsQuery['site']['products']['edges']
|
||||||
? NonNullable<T['site']['products']['edges']>
|
>
|
||||||
: unknown
|
|
||||||
}
|
export type GetAllProductPathsResult<
|
||||||
|
T extends { products: any[] } = { products: ProductPaths }
|
||||||
|
> = T
|
||||||
|
|
||||||
async function getAllProductPaths(opts?: {
|
async function getAllProductPaths(opts?: {
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
}): Promise<GetAllProductPathsResult<GetAllProductPathsQuery>>
|
}): Promise<GetAllProductPathsResult>
|
||||||
|
|
||||||
async function getAllProductPaths<T, V = any>(opts: {
|
async function getAllProductPaths<
|
||||||
|
T extends { products: any[] },
|
||||||
|
V = any
|
||||||
|
>(opts: {
|
||||||
query: string
|
query: string
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
}): Promise<GetAllProductPathsResult<T>>
|
}): Promise<GetAllProductPathsResult<T>>
|
||||||
@ -37,7 +42,7 @@ async function getAllProductPaths({
|
|||||||
}: {
|
}: {
|
||||||
query?: string
|
query?: string
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
} = {}): Promise<GetAllProductPathsResult<GetAllProductPathsQuery>> {
|
} = {}): Promise<GetAllProductPathsResult> {
|
||||||
config = getConfig(config)
|
config = 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 `query`
|
// required in case there's a custom `query`
|
||||||
|
@ -37,11 +37,13 @@ export const getAllProductsQuery = /* GraphQL */ `
|
|||||||
${productInfoFragment}
|
${productInfoFragment}
|
||||||
`
|
`
|
||||||
|
|
||||||
export interface GetAllProductsResult<T> {
|
export type Products = NonNullable<
|
||||||
products: T extends GetAllProductsQuery
|
GetAllProductsQuery['site']['products']['edges']
|
||||||
? NonNullable<T['site']['products']['edges']>
|
>
|
||||||
: unknown
|
|
||||||
}
|
export type GetAllProductsResult<
|
||||||
|
T extends { products: any[] } = { products: Products }
|
||||||
|
> = T
|
||||||
|
|
||||||
export type ProductVariables = Images &
|
export type ProductVariables = Images &
|
||||||
Omit<GetAllProductsQueryVariables, keyof ProductImageVariables>
|
Omit<GetAllProductsQueryVariables, keyof ProductImageVariables>
|
||||||
@ -49,9 +51,9 @@ export type ProductVariables = Images &
|
|||||||
async function getAllProducts(opts?: {
|
async function getAllProducts(opts?: {
|
||||||
variables?: ProductVariables
|
variables?: ProductVariables
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
}): Promise<GetAllProductsResult<GetAllProductsQuery>>
|
}): Promise<GetAllProductsResult>
|
||||||
|
|
||||||
async function getAllProducts<T, V = any>(opts: {
|
async function getAllProducts<T extends { products: any[] }, V = any>(opts: {
|
||||||
query: string
|
query: string
|
||||||
variables?: V
|
variables?: V
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
@ -65,7 +67,7 @@ async function getAllProducts({
|
|||||||
query?: string
|
query?: string
|
||||||
variables?: ProductVariables
|
variables?: ProductVariables
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
} = {}): Promise<GetAllProductsResult<GetAllProductsQuery>> {
|
} = {}): Promise<GetAllProductsResult> {
|
||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
const variables: GetAllProductsQueryVariables = {
|
const variables: GetAllProductsQueryVariables = {
|
||||||
...config.imageVariables,
|
...config.imageVariables,
|
||||||
|
@ -50,7 +50,7 @@ async function getProduct(opts: {
|
|||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
}): Promise<GetProductResult>
|
}): Promise<GetProductResult>
|
||||||
|
|
||||||
async function getProduct<T, V = any>(opts: {
|
async function getProduct<T extends { product?: any }, V = any>(opts: {
|
||||||
query: string
|
query: string
|
||||||
variables: V
|
variables: V
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
|
Loading…
x
Reference in New Issue
Block a user