datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 51 forks source link

Getting duplicated records for the untranslated contents #125

Closed fatihky closed 3 years ago

fatihky commented 4 years ago

Hi, I have one content type (Article) and two locales. I've added two articles and both have only one translation. One has the only English translation, one has the only Turkish translation. But it seems, at gatsby side, records have null copies for Turkish and English if they were not translated to that language. I'd expect no record at all for the language that record hasn't been translated to.

The environment:

Graphql query I run:

query MyQuery {
  allDatoCmsArticle {
    nodes {
      title
      slug
      originalId
      locale
    }
  }
}

Result:

{
  "data": {
    "allDatoCmsArticle": {
      "nodes": [
        {
          "title": null,
          "slug": null,
          "originalId": "7403849",
          "locale": "en"
        },
        {
          "title": "Only Turkish",
          "slug": "only-turkish",
          "originalId": "7403849",
          "locale": "tr"
        },
        {
          "title": "Only English",
          "slug": "only-english",
          "originalId": "7403847",
          "locale": "en"
        },
        {
          "title": null,
          "slug": null,
          "originalId": "7403847",
          "locale": "tr"
        }
      ]
    }
  },
  "extensions": {}
}

Another query for getting Turkish content:

query MyQuery {
  allDatoCmsArticle(filter: { locale: { eq: "tr" } }) {
    nodes {
      title
      slug
      originalId
      locale
    }
  }
}

Result:

{
  "data": {
    "allDatoCmsArticle": {
      "nodes": [
        {
          "title": "Only Turkish",
          "slug": "only-turkish",
          "originalId": "7403849",
          "locale": "tr"
        },
        {
          "title": null,
          "slug": null,
          "originalId": "7403847",
          "locale": "tr"
        }
      ]
    }
  },
  "extensions": {}
}

BTW, I can avoid that null records by querying slug with regex. For example, if I run this query, I get my expected result:

query MyQuery {
  allDatoCmsArticle(filter: { slug: { regex: "/.+/" }, locale: { eq: "tr" } }) {
    nodes {
      title
      slug
      originalId
      locale
    }
  }
}

Result:

{
  "data": {
    "allDatoCmsArticle": {
      "nodes": [
        {
          "title": "Only Turkish",
          "slug": "only-turkish",
          "originalId": "7403849",
          "locale": "tr"
        }
      ]
    }
  },
  "extensions": {}
}
matjack1 commented 3 years ago

Hello,

yes, right now if a record has an untranslated locale, we'll return an empty object for that.

I hope you can deal with this on your end, sorry.