Query for linked records that do not have target locale returns NULL objects

Hi there. I have just noticed that GraphQL will return null objects on the linked records when filtering with locale and if the linked record does not contain the content in this locale.

For example this query

query MyQuery {
  allFooterMenus(locale: en, filter: {id: {eq: "116657210"}}) {
    id
    title
    links {
      ... on BlogPostRecord {
        slug
      }
    }
  }
}

will return on EN this:

{
  "data": {
    "allFooterMenus": [
      {
        "id": "116657210",
        "title": "Articles",
        "links": [
          {
            "slug": "test-article"
          },
          {
            "slug": "dewesoftx-2022-2-released"
          }
        ]
      }
    ]
  }
}

but with locale (e.g. fr) will return empty objects like this (because linked records do not have FR locale translated yet):

{
  "data": {
    "allFooterMenus": [
      {
        "id": "116657210",
        "title": "Des articles",
        "links": [
          {
            "slug": null
          },
          {
            "slug": null
          }
        ]
      }
    ]
  }
}

Wouldn’t it be better if this returned an empty array instead of NULL objects? This way the logic would not have to be moved to front-end code, wether some content exist in locale or not.

Hello @primoz.rome the locale parameter that you are passing there is not a filter. It’s a way to get the content in that particular locale, but the filtering happens afterwards.

In any case, I’ve checked your model and links is a non translated field. So what happens is that the records are there in all locales, but then if you fetch the slug field from that record is null in the specific locale.

To me this makes sense though as the records are present in the first place, so returning an empty array seems incorrect to me.

What do you think?

In any case, I’ve checked your model and links is a non translated field.

Yes that is correct. I am using non-translated links filed in this case. This is for one reason. I don’t have to repeat all links in all locales. Time consuming! It is very convenient that DatoCMS is returning translated content for links that do exist in target locale. But for those that do not returns null.

To me this makes sense though as the records are present in the first place, so returning an empty array seems incorrect to me.

Well in my eyes both ways are correct to me, depends from which angle you are looking at this. I am not 100% in which case you would need those empty objects on front-end in the first place. In my scenario I would prefer to see empty array.

Either way I can do a work-around… have the links field translatable, and I set up all the links on every locale.

Kind regards,
Primoz

the rationale behind is that if the record is present we return it. Then if you pick a field that is not existent we return null.

We would have returned an empty array in case the translation wasn’t present, but it’s not your case.

I hope you appreciate the difference?

We would have returned an empty array in case the translation wasn’t present, but it’s not your case.

Hmm @mat_jack1 but that is the situation in my case. The record is there, but has no translation to target locale. Or am I missing something?

It’s not your case because you have the intermediate non-translated field.

Translated records → non-translated field → translated record

So, independently from the translation you are in at the source, you always have the same linked record. Then you need to get again the translation, but the record is always going to be there, you see?

Hi @mat_jack1 … would you have 10 minutes next week for a quick call, and we discuss this on actual data. It will be also easier for me to understand and/or show you what I mean.

Hey @primoz.rome sorry I was away last week, but I’m back! Feel free to book a call with me here: Calendly - DatoCMS

cheers

1 Like