From 051355ba6a74a5b6ace498770fa3a4543d659728 Mon Sep 17 00:00:00 2001 From: Anders Gustafsson <34234789+anders-photowall@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:48:44 +0100 Subject: [PATCH] 4257 - add multi locale support to categories resolver (#161) --- src/datasources/category-api.ts | 6 +++--- src/resolvers/categories-resolver.ts | 4 ++-- src/schema.graphql | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/datasources/category-api.ts b/src/datasources/category-api.ts index c29a019..b8b8f6b 100644 --- a/src/datasources/category-api.ts +++ b/src/datasources/category-api.ts @@ -125,13 +125,13 @@ WHERE product_category.product_id = ? async getLocaleDataForId( id: number, - locale?: string, + locales?: string[], ): Promise { // Dataloaders does not need scopes validation since they // use other functions. const res = await this.localeDataLoader.load(id); - if (locale) { - return res.filter((row) => row.locale === locale); + if (locales) { + return res.filter((row) => locales.includes(row.locale)); } return res; } diff --git a/src/resolvers/categories-resolver.ts b/src/resolvers/categories-resolver.ts index 8e7e905..322b5b5 100644 --- a/src/resolvers/categories-resolver.ts +++ b/src/resolvers/categories-resolver.ts @@ -14,10 +14,10 @@ const Category = { async localeNames({ id }, _, { dataSources }) { return (dataSources.categoryApi).getLocaleNameForId(id); }, - async localeData({ id }, input: { locale: string }, { dataSources }) { + async localeData({ id }, input: { locales: string[] }, { dataSources }) { return (dataSources.categoryApi).getLocaleDataForId( id, - input.locale, + input.locales, ); }, }; diff --git a/src/schema.graphql b/src/schema.graphql index 8c31c6a..527f7dd 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -230,7 +230,7 @@ type Category { """ products(includeAllSubCategories: Boolean): [Product] localeNames: JSON - localeData(locale: String): [CategoryLocaleData]! + localeData(locales: [String]!): [CategoryLocaleData]! } type Batch {