Is there a way to retrieve content for a backup / fallback language with GraphQL?
For example, my default language Prismic language is "en-us", but we will have the data in many languages.
If a language exists in our Prismic CMS, 'de-de' for example, but a certain page has only been created in English, when a user requests this page in 'de-de' via GraphQL a null object is returned. e.g.
Hi @tim, thanks for reaching out about this. Unfortunately there isn’t a way to have the GraphQL API (or the REST API for anyone else curious) return a backup document if the language you’re looking for doesn’t exist. This will have to be done in your website application. That is, if you don’t find a document in the language you’re looking for (it return null), then run a second query for the document in the default language (“en-us” in your case).
Let me know if you have any questions about this. Thanks!
No worries, that makes sense, and I’m already building in this logic into the app.
e.g. if it returns null then I make a second request with the default language.
Hi @tim, just an alternative practice. Instead of to call the default language (your backup, fallback language) only if the language you’re looking for doesn’t exist, you can check this scenario every time for your content. If use nodejs/javascript and REST API, for example, you can use a Promise.all to get the content in current language and in the fallback language. If the first response does not contains results, return the second response:
I am currently doing something similar, but a little bit longer as I’m using Apollo. I like the idea of utilising promises in this way though, it seems much cleaner.
I’ll see what I can do with Apollo and post my solution back here when I’m successful!
1 Like
Fares
closed , flag & select 'Something Else' to reopen.
6