mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-06-07 21:59:54 +00:00
fix: Handle variable lang directive (#272)
This commit is contained in:
parent
3d5beb1f76
commit
a835c6ca29
@ -10,10 +10,25 @@ const middleware = <Q extends Record<string, any> = Record<string, any>>(fn: (la
|
|||||||
_: any,
|
_: any,
|
||||||
e: any
|
e: any
|
||||||
) => {
|
) => {
|
||||||
let lang = e?.fieldNodes?.[0]?.directives?.[0]?.arguments?.[0]?.value?.value
|
|
||||||
if (!lang) {
|
// get the locale directive
|
||||||
lang = 'en'
|
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)) {
|
if (!checkLanguage(lang)) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user