Gatsby: [gatsby-source-contentful] Cannot get to localized nodes via References

Created on 21 Feb 2018  路  2Comments  路  Source: gatsbyjs/gatsby

Description

I am trying to create multi-language site using contentful as the headless CMS. I have setup the contentful content model as follows:

The Navigation content type has a title and a links field, which references many Links.
The Link content type has a title field (localized) and a page field, which references one Page.
The Page content type has a title field (localized) and a text field (localized).

When rendering page, I want to render the main navigation depending on the locale of each page, so that the links in the main navigation point to localized pages - if available - instead of pages written in the default locale.

Environment

Gatsby version: ^1.9.158
Node.js version: v9.4.0
Operating System: macOS 10.13.3

File contents (if changed)

The file contents shouldn't matter, I can add them later if requested.

GraphQL query

To retrieve the main navigation, I use the following query in the page.js template:

query PageQuery($id:String!){
  main:contentfulNavigation(contentful_id:{eq:$id}) {
    links {
      title
      node_locale
      page {
        slug
      }
    }
  }
}

Actual result

I tested this query in GraphiQL and this is what I received:

{
  "data": {
    "main": {
      "links": [
        {
          "title": "脺ber uns",
          "node_locale": "de-DE",
          "page": {
            "slug": "/about-us"
          }
        },
        {
          "title": "Kontakt",
          "node_locale": "de-DE",
          "page": {
            "slug": "/contact"
          }
        }
      ]
    }
  }
}

Expected behavior

The response does not contain the localized nodes, only the nodes with the default locale (de-DE). I expect nodes for the secondary locale (en) to be included:

{
  "data": {
    "main": {
      "links": [
        {
          "title": "脺ber uns",
          "node_locale": "de-DE",
          "page": {
            "slug": "/about-us"
          }
        },
        {
          "title": "Kontakt",
          "node_locale": "de-DE",
          "page": {
            "slug": "/contact"
          }
        },
          "title": "About us",
          "node_locale": "en",
          "page": {
            "slug": "/about-us"
          }
        },
          "title": "Contact",
          "node_locale": "en",
          "page": {
            "slug": "/contact"
          }
        },
      ]
    }
  }
}

Steps to reproduce

1. Create a contentful content type A, which itself has no localized fields and references another content type B, which has localized fields.

2. Try to retrieve the referenced entries of type B by querying an entry of type A. The response will only include the entries of type B in the default locale. Other locales are missing.

Most helpful comment

I was able to get localized nodes by using a filter in my query. I have two node_locale in Contentful. Hope it's useful:

Query

{
  allContentfulBlogPost(
    filter: {node_locale: {regex: "/da-DK/"}}
  ) {
    edges {
      node {
        title
      }
    }
  }
}

output

{
  "data": {
    "allContentfulBlogPost": {
      "edges": [
        {
          "node": {
            "title": "Ny Blog Post - Juhuuu"
          }
        }
      ]
    }
  }
}

All 2 comments

I was able to get localized nodes by using a filter in my query. I have two node_locale in Contentful. Hope it's useful:

Query

{
  allContentfulBlogPost(
    filter: {node_locale: {regex: "/da-DK/"}}
  ) {
    edges {
      node {
        title
      }
    }
  }
}

output

{
  "data": {
    "allContentfulBlogPost": {
      "edges": [
        {
          "node": {
            "title": "Ny Blog Post - Juhuuu"
          }
        }
      ]
    }
  }
}

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jimfilippou picture jimfilippou  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

benstr picture benstr  路  3Comments

totsteps picture totsteps  路  3Comments