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

Locale at query level returns wrong fields #209

Closed
jgdemattos opened this issue Dec 21, 2022 · 3 comments · Fixed by #211
Closed

Locale at query level returns wrong fields #209

jgdemattos opened this issue Dec 21, 2022 · 3 comments · Fixed by #211

Comments

@jgdemattos
Copy link

Issue when querying a document with the locale argument at document level, like the the query below:

query BlogPostByOriginalId($language: String!, $originalId: String!) {
  datoCmsBlogpost(originalId: {eq: $originalId}, locale: $language) {
    originalId
    title
  }
}

This query will, sometimes, ramdomly return fields in the wrong language when building the site. This happens mostly in production.

As an example, if the $language is PT, portuguese, I will get fields in EN, english.

The safe way to ensure the correct field language, is to use the locale argument at field level, like below:

query BlogPostByOriginalId($language: String!, $originalId: String!) {
  datoCmsBlogpost(originalId: {eq: $originalId}, locale: $language) {
    originalId
    title(locale: $postLang)
  }
}
@vanska
Copy link

vanska commented Dec 27, 2022

I'm facing the same issue.

If a locale is not defined on a field level the secondary locale is returned even if a fallback locale is set to the primary locale.

Doesn't affect development.

@Faxxiz
Copy link

Faxxiz commented Dec 29, 2022

Facing the same issue, not on a development but on every build.

export const pageQuery = graphql`
  query HomePage($locale: String!) {
    datoCmsGlobalConfiguration(locale: $locale) {
      id
      websiteName
      ...CookiesBannerFields
    }
  }
`

here is my gatsby-node just to show that I'm creating the same page on different languages :

async function generateHomePage() {
  const index = path.resolve(`./src/templates/index.tsx`)

  allLocales.data.datoCmsSite.locales.forEach(locale => {
    createPage({
      path: locale === defaultLocale ? "/" : `/${locale}`,
      component: index,
      context: {
        locale,
        defaultLocale,
        slugs: allMainSlugs,
      },
    })
  })
}

and as you can see in my context the locale is "fr" and the data returned is in english

Capture d’écran du 2022-12-29 10-04-14

@pieh
Copy link
Contributor

pieh commented Jan 9, 2023

Hey folks, I opened PR with potential fix for those issues in #211

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

Successfully merging a pull request may close this issue.

4 participants