1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-04-22 19:02:10 +00:00

fix: Handle variable lang directive (#272)

This commit is contained in:
Florian Bouillon 2022-04-11 12:17:22 +02:00 committed by GitHub
parent 3d5beb1f76
commit a835c6ca29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,10 +10,25 @@ const middleware = <Q extends Record<string, any> = Record<string, any>>(fn: (la
_: any,
e: any
) => {
let lang = e?.fieldNodes?.[0]?.directives?.[0]?.arguments?.[0]?.value?.value
if (!lang) {
lang = 'en'
// get the locale directive
const langArgument = e?.fieldNodes?.[0]?.directives?.[0]?.arguments?.[0]?.value
// if there is no locale directive
if (!langArgument) {
return fn('en', data)
}
// set default locale directive value
let lang = 'en'
// handle variable for directive value
if (langArgument.kind === 'Variable') {
lang = e.variableValues[langArgument.name.value]
} else {
lang = langArgument.value
}
if (!checkLanguage(lang)) {
return undefined
}