How to Flatten Translation Fields in Directus GraphQL Response (Field: entries)
Hi everyone ![]()
I’m using Directus with GraphQL and trying to simplify the structure of a multilingual response. We have a collection (nav) with translations handled through a field called entries, which is a relational field that holds localized content.
Here’s the GraphQL query we’re using:
query GetNav($lang: String!) {
nav {
uuid
entries(filter: {languages_code: {code: {_eq: $lang}}}) {
title
}
}
}
And the current response looks like this:
{
"data": {
"nav": [
{
"uuid": "1ce10140-f646-40a8-bf2a-51ef21e212df",
"entries": [
{
"title": "en"
}
]
}
]
}
}
We would like to flatten the entries field and return something like this instead:
{
"data": {
"nav": [
{
"uuid": "1ce10140-f646-40a8-bf2a-51ef21e212df",
"title": "en"
}
]
}
}
I understand that entries is a relation (probably 1:N), but since it always returns only one translation per language, we’d love to know if there’s a way to flatten or alias it in the GraphQL response without having to do it manually in frontend code.
Thanks in advance for any ideas or best practices! ![]()