I have a specific situation where I have a method that getting an object as follow
async ({ locale }, ctx) => {
const lang = await LanguageService(ctx).getLanguage({
locale,
});
return lang.direction ? 'rtl' : 'ltr';
},
The { locale } is equal to a request as locale: en_US.
The next method I need to use getLanguage accepts { locale } but I have to pass only the en.
So I thought to do slice but if I send it as for example
const sliced = locale.slice(0,2)
const lang = await LanguageService(ctx).getLanguage({
sliced, // or locale: sliced
});
From the next method the locale is showed as undefined and I have no clue how to pass only en in this situation I have
The method getLanguage
async getLanguage({ id, locale }) {
console.log('locale: ', locale);
if (!id && !locale) {
const errorMessage = 'Specify ID or locale';
throw new ApolloError(errorMessage);
}
const filter = id ? { id } : { locale };
try {
return await this.withDAO(({ languages }) =>
languages.selectFirst(filter)
);
} catch (error) {
throw new ApolloError(error.message);
}
}
This method needs { locale } and I need to pass en and not en_US
I have no clue how to reach that as when I reach this above method the console.log(locale) is showing undefined when I use slice.
There is a way I can use that obj in the way I need