Apply prettier over all files
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { GetAllProductPathsQuery } from 'lib/bigcommerce/schema';
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types';
|
||||
import { BigcommerceConfig, getConfig } from '..';
|
||||
import type { GetAllProductPathsQuery } from 'lib/bigcommerce/schema'
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types'
|
||||
import { BigcommerceConfig, getConfig } from '..'
|
||||
|
||||
export const getAllProductPathsQuery = /* GraphQL */ `
|
||||
query getAllProductPaths {
|
||||
@@ -14,41 +14,41 @@ export const getAllProductPathsQuery = /* GraphQL */ `
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
`
|
||||
|
||||
export interface GetAllProductPathsResult<T> {
|
||||
products: T extends GetAllProductPathsQuery
|
||||
? NonNullable<T['site']['products']['edges']>
|
||||
: unknown;
|
||||
: unknown
|
||||
}
|
||||
|
||||
async function getAllProductPaths(opts?: {
|
||||
query?: string;
|
||||
config?: BigcommerceConfig;
|
||||
}): Promise<GetAllProductPathsResult<GetAllProductPathsQuery>>;
|
||||
query?: string
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetAllProductPathsResult<GetAllProductPathsQuery>>
|
||||
|
||||
async function getAllProductPaths<T, V = any>(opts: {
|
||||
query: string;
|
||||
config?: BigcommerceConfig;
|
||||
}): Promise<GetAllProductPathsResult<T>>;
|
||||
query: string
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetAllProductPathsResult<T>>
|
||||
|
||||
async function getAllProductPaths({
|
||||
query = getAllProductPathsQuery,
|
||||
config = getConfig(),
|
||||
}: {
|
||||
query?: string;
|
||||
config?: BigcommerceConfig;
|
||||
query?: string
|
||||
config?: BigcommerceConfig
|
||||
} = {}): Promise<GetAllProductPathsResult<GetAllProductPathsQuery>> {
|
||||
// RecursivePartial forces the method to check for every prop in the data, which is
|
||||
// required in case there's a custom `query`
|
||||
const data = await config.fetch<RecursivePartial<GetAllProductPathsQuery>>(
|
||||
query
|
||||
);
|
||||
const products = data.site?.products?.edges;
|
||||
)
|
||||
const products = data.site?.products?.edges
|
||||
|
||||
return {
|
||||
products: (products as RecursiveRequired<typeof products>) ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default getAllProductPaths;
|
||||
export default getAllProductPaths
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import type {
|
||||
GetAllProductsQuery,
|
||||
GetAllProductsQueryVariables,
|
||||
} from 'lib/bigcommerce/schema';
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types';
|
||||
import { productInfoFragment } from '../fragments/product';
|
||||
import {
|
||||
BigcommerceConfig,
|
||||
getConfig,
|
||||
Images,
|
||||
ProductImageVariables,
|
||||
} from '..';
|
||||
} from 'lib/bigcommerce/schema'
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types'
|
||||
import { productInfoFragment } from '../fragments/product'
|
||||
import { BigcommerceConfig, getConfig, Images, ProductImageVariables } from '..'
|
||||
|
||||
export const getAllProductsQuery = /* GraphQL */ `
|
||||
query getAllProducts(
|
||||
@@ -40,53 +35,53 @@ export const getAllProductsQuery = /* GraphQL */ `
|
||||
}
|
||||
|
||||
${productInfoFragment}
|
||||
`;
|
||||
`
|
||||
|
||||
export interface GetAllProductsResult<T> {
|
||||
products: T extends GetAllProductsQuery
|
||||
? NonNullable<T['site']['products']['edges']>
|
||||
: unknown;
|
||||
: unknown
|
||||
}
|
||||
|
||||
export type ProductVariables = Images &
|
||||
Omit<GetAllProductsQueryVariables, keyof ProductImageVariables>;
|
||||
Omit<GetAllProductsQueryVariables, keyof ProductImageVariables>
|
||||
|
||||
async function getAllProducts(opts?: {
|
||||
query?: string;
|
||||
variables?: ProductVariables;
|
||||
config?: BigcommerceConfig;
|
||||
}): Promise<GetAllProductsResult<GetAllProductsQuery>>;
|
||||
query?: string
|
||||
variables?: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetAllProductsResult<GetAllProductsQuery>>
|
||||
|
||||
async function getAllProducts<T, V = any>(opts: {
|
||||
query: string;
|
||||
variables?: V;
|
||||
config?: BigcommerceConfig;
|
||||
}): Promise<GetAllProductsResult<T>>;
|
||||
query: string
|
||||
variables?: V
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetAllProductsResult<T>>
|
||||
|
||||
async function getAllProducts({
|
||||
query = getAllProductsQuery,
|
||||
variables: vars,
|
||||
config = getConfig(),
|
||||
}: {
|
||||
query?: string;
|
||||
variables?: ProductVariables;
|
||||
config?: BigcommerceConfig;
|
||||
query?: string
|
||||
variables?: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
} = {}): Promise<GetAllProductsResult<GetAllProductsQuery>> {
|
||||
const variables: GetAllProductsQueryVariables = {
|
||||
...config.imageVariables,
|
||||
...vars,
|
||||
};
|
||||
}
|
||||
// RecursivePartial forces the method to check for every prop in the data, which is
|
||||
// required in case there's a custom `query`
|
||||
const data = await config.fetch<RecursivePartial<GetAllProductsQuery>>(
|
||||
query,
|
||||
{ variables }
|
||||
);
|
||||
const products = data.site?.products?.edges;
|
||||
)
|
||||
const products = data.site?.products?.edges
|
||||
|
||||
return {
|
||||
products: (products as RecursiveRequired<typeof products>) ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default getAllProducts;
|
||||
export default getAllProducts
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type {
|
||||
GetProductQuery,
|
||||
GetProductQueryVariables,
|
||||
} from 'lib/bigcommerce/schema';
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types';
|
||||
import { productInfoFragment } from '../fragments/product';
|
||||
import { BigcommerceConfig, getConfig, Images } from '..';
|
||||
} from 'lib/bigcommerce/schema'
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types'
|
||||
import { productInfoFragment } from '../fragments/product'
|
||||
import { BigcommerceConfig, getConfig, Images } from '..'
|
||||
|
||||
export const getProductQuery = /* GraphQL */ `
|
||||
query getProduct(
|
||||
@@ -31,55 +31,55 @@ export const getProductQuery = /* GraphQL */ `
|
||||
}
|
||||
|
||||
${productInfoFragment}
|
||||
`;
|
||||
`
|
||||
|
||||
export interface GetProductResult<T> {
|
||||
product?: T extends GetProductQuery
|
||||
? Extract<T['site']['route']['node'], { __typename: 'Product' }>
|
||||
: unknown;
|
||||
: unknown
|
||||
}
|
||||
|
||||
export type ProductVariables = Images &
|
||||
({ path: string; slug?: never } | { path?: never; slug: string });
|
||||
({ path: string; slug?: never } | { path?: never; slug: string })
|
||||
|
||||
async function getProduct(opts: {
|
||||
query?: string;
|
||||
variables: ProductVariables;
|
||||
config?: BigcommerceConfig;
|
||||
}): Promise<GetProductResult<GetProductQuery>>;
|
||||
query?: string
|
||||
variables: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetProductResult<GetProductQuery>>
|
||||
|
||||
async function getProduct<T, V = any>(opts: {
|
||||
query: string;
|
||||
variables: V;
|
||||
config?: BigcommerceConfig;
|
||||
}): Promise<GetProductResult<T>>;
|
||||
query: string
|
||||
variables: V
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetProductResult<T>>
|
||||
|
||||
async function getProduct({
|
||||
query = getProductQuery,
|
||||
variables: { slug, ...vars },
|
||||
config = getConfig(),
|
||||
}: {
|
||||
query?: string;
|
||||
variables: ProductVariables;
|
||||
config?: BigcommerceConfig;
|
||||
query?: string
|
||||
variables: ProductVariables
|
||||
config?: BigcommerceConfig
|
||||
}): Promise<GetProductResult<GetProductQuery>> {
|
||||
const variables: GetProductQueryVariables = {
|
||||
...config.imageVariables,
|
||||
...vars,
|
||||
path: slug ? `/${slug}/` : vars.path!,
|
||||
};
|
||||
}
|
||||
const data = await config.fetch<RecursivePartial<GetProductQuery>>(query, {
|
||||
variables,
|
||||
});
|
||||
const product = data.site?.route?.node;
|
||||
})
|
||||
const product = data.site?.route?.node
|
||||
|
||||
if (product?.__typename === 'Product') {
|
||||
return {
|
||||
product: product as RecursiveRequired<typeof product>,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
return {}
|
||||
}
|
||||
|
||||
export default getProduct;
|
||||
export default getProduct
|
||||
|
||||
Reference in New Issue
Block a user