forked from crowetic/commerce
Fix
This commit is contained in:
parent
2a29cfe3c7
commit
9ca977c44f
@ -17,8 +17,8 @@ export interface GetAllProductsResult<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class BigcommerceAPI implements CommerceAPI {
|
export default class BigcommerceAPI implements CommerceAPI {
|
||||||
protected commerceUrl: string;
|
commerceUrl: string;
|
||||||
protected apiToken: string;
|
apiToken: string;
|
||||||
|
|
||||||
constructor({ commerceUrl, apiToken }: CommerceAPIOptions) {
|
constructor({ commerceUrl, apiToken }: CommerceAPIOptions) {
|
||||||
this.commerceUrl = commerceUrl;
|
this.commerceUrl = commerceUrl;
|
||||||
@ -52,24 +52,20 @@ export default class BigcommerceAPI implements CommerceAPI {
|
|||||||
async getAllProducts<T>(opts: {
|
async getAllProducts<T>(opts: {
|
||||||
query: string;
|
query: string;
|
||||||
}): Promise<GetAllProductsResult<T>>;
|
}): Promise<GetAllProductsResult<T>>;
|
||||||
async getAllProducts<T = GetAllProductsQuery>({
|
|
||||||
query,
|
|
||||||
}: { query?: string } = {}): Promise<
|
|
||||||
GetAllProductsResult<T | GetAllProductsQuery>
|
|
||||||
// T extends GetAllProductsQuery
|
|
||||||
// ? GetAllProductsResult<T['site']['products']['edges']>
|
|
||||||
// : Partial<GetAllProductsResult<any>>
|
|
||||||
> {
|
|
||||||
if (!query) {
|
|
||||||
const data = await this.fetch<GetAllProductsQuery>(getAllProductsQuery);
|
|
||||||
|
|
||||||
return {
|
async getAllProducts(opts?: {
|
||||||
products: data.site.products.edges,
|
query?: string;
|
||||||
};
|
}): Promise<GetAllProductsResult<GetAllProductsQuery>>;
|
||||||
}
|
|
||||||
|
async getAllProducts({
|
||||||
|
query = getAllProductsQuery,
|
||||||
|
}: { query?: string } = {}): Promise<
|
||||||
|
GetAllProductsResult<RecursivePartial<GetAllProductsQuery>>
|
||||||
|
> {
|
||||||
|
const data = await this.fetch<RecursivePartial<GetAllProductsQuery>>(query);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
products: undefined,
|
products: data?.site?.products?.edges,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user