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:
parent
3d5beb1f76
commit
a835c6ca29
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user