Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: figure out how to output text in both languages #369

Open
AlexCLeduc opened this issue Aug 8, 2024 · 0 comments
Open

API: figure out how to output text in both languages #369

AlexCLeduc opened this issue Aug 8, 2024 · 0 comments
Labels

Comments

@AlexCLeduc
Copy link
Contributor

A few ideas,

Preferred approach: BilingualString Object type

  • create a graphql BilingiaulString object type
  • it has en and fr string fields,
  • most user-text defined string fields get turned into BilingualString types
query {
    indicators {
       name { 
         en 
       }
    }

}

The only problem I find here is that, if they only want to fetch english or french values, they have to use different queries rather than supply a different argument. They could do string replaces or something like that, but that's kind of a graphql anti-pattern because graphql strings should be statically analyzable.

It may also be annoying to constantly have to specify you want english data

Alternative: Declaring a language in the root of the query, e.g.

query {
    extra_root_layer(lang: "en"){ # find a better name for this root layer
         indicator {
           name # correspond to name_en in DB
         }
    } 
}

here, the root layer's resolver would add language:"en" on the context,

This seems like a quick and dirty fix, but it's kind of bad, because there's only one context and people might ask for 2 "root" objects of different languages. You could store this elsewhere than the context, e.g. a resolver decorator can look at the query's ancestor chain via the info argument, and infer the desired language, but that's also complex. Even if we did this, you also can't (easily) get data in 2 languages in one query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant