Carson Schwalm
Carson Schwalm

Reputation: 31

Contentful graphql api not fetching localized `linkedfrom` items

Basically I want to get localized values for the entries linking to my unique entry.

movie(id: $movieId) {
  linkedFrom {
    spanishMovieLocations: movieLocationCollection(locale: "es-ES") { 
      items {//fields with localized values} 
    }
  }
}

But instead I get no results in my collection array. Querying directly for movieLocationCollection(locale: "es-ES") gets me localized values and has some matching movie.sys.id that is used in $movieId.

This works fine, but then I dont get the localized fields I need.

movie(id: $movieId) {
  linkedFrom {
    movieLocationCollection { 
      items {//fields with non-localized values} 
    }
  }
}

Upvotes: 3

Views: 1328

Answers (1)

Gregory Elward
Gregory Elward

Reputation: 31

from the contentful site:

We ... made the querying of localized reference content easier by introducing a new allowedLocales argument.

https://www.contentful.com/blog/2020/12/03/three-new-graphql-features-2020/

movie(id: $movieId) {
  linkedFrom(allowedLocales: ["es-ES"]) {
    movieLocationCollection { 
      items {//fields with non-localized values} 
    }
  }
}

In my project I had to include both locales

query ($parner: String) { 
  partnerCollection(limit: 1, locale: "fr-CA", where: {title: $parner}) {
    items {
      title
      sys {
        id
      }
      linkedFrom(allowedLocales: ["en-US", "fr-CA"]) {
        benefitCollection(limit: 3) {
          total
          items {
            title
          }
        }
      }
    }
  }
}

Upvotes: 3

Related Questions