Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-source-contentful] Cannot get to localized nodes via References #4168

Closed
anjawaldbauer opened this issue Feb 21, 2018 · 2 comments
Closed

Comments

@anjawaldbauer
Copy link
Contributor

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.

@WolffDev
Copy link

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"
          }
        }
      ]
    }
  }
}

@KyleAMathews
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants