4257 - add multi locale support to categories resolver (#161)

This commit is contained in:
Anders Gustafsson
2024-01-09 14:48:44 +01:00
committed by GitHub
parent 2a9b7a88ee
commit 051355ba6a
3 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -125,13 +125,13 @@ WHERE product_category.product_id = ?
async getLocaleDataForId( async getLocaleDataForId(
id: number, id: number,
locale?: string, locales?: string[],
): Promise<CategoryLocaleData[]> { ): Promise<CategoryLocaleData[]> {
// Dataloaders does not need scopes validation since they // Dataloaders does not need scopes validation since they
// use other functions. // use other functions.
const res = await this.localeDataLoader.load(id); const res = await this.localeDataLoader.load(id);
if (locale) { if (locales) {
return res.filter((row) => row.locale === locale); return res.filter((row) => locales.includes(row.locale));
} }
return res; return res;
} }
+2 -2
View File
@@ -14,10 +14,10 @@ const Category = {
async localeNames({ id }, _, { dataSources }) { async localeNames({ id }, _, { dataSources }) {
return (<CategoryAPI>dataSources.categoryApi).getLocaleNameForId(id); return (<CategoryAPI>dataSources.categoryApi).getLocaleNameForId(id);
}, },
async localeData({ id }, input: { locale: string }, { dataSources }) { async localeData({ id }, input: { locales: string[] }, { dataSources }) {
return (<CategoryAPI>dataSources.categoryApi).getLocaleDataForId( return (<CategoryAPI>dataSources.categoryApi).getLocaleDataForId(
id, id,
input.locale, input.locales,
); );
}, },
}; };
+1 -1
View File
@@ -230,7 +230,7 @@ type Category {
""" """
products(includeAllSubCategories: Boolean): [Product] products(includeAllSubCategories: Boolean): [Product]
localeNames: JSON localeNames: JSON
localeData(locale: String): [CategoryLocaleData]! localeData(locales: [String]!): [CategoryLocaleData]!
} }
type Batch { type Batch {