Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Davy Lowyck 8 posts 110 karma points
    Nov 02, 2020 @ 14:27
    Davy Lowyck
    0

    Get other language version urls via Heartcore GraphQL

    Hi,

    I am considering using GraphQL instead of the standard Heartcore content API to get heartcore content for my frontend.

    I have noticed that the content API returns a _urls field for every item, which shows the item's URL in all of the languages, and that field seems to be missing in the GraphQL implementation.

    Since I want to implement hreflang in my frontend, I need the urls of the language variants. How can I get this data, without using multiple queries (per locale) in GraphQL?

    Kind regards,

  • Gerhard Grossberger 54 posts 178 karma points
    Nov 05, 2020 @ 11:48
    Gerhard Grossberger
    0

    Hey Davy, I really can´t add anything to your question, but I tried to only get those articles available in a certain language. I managed that setting the header in API-Browser, but couldn´t find anything in the documentation about culture.

    How do you actually set the culture in GraphQL fo Heartcore?

    Best, Gerhard

  • Gerhard Grossberger 54 posts 178 karma points
    Nov 05, 2020 @ 11:54
    Gerhard Grossberger
    0

    Figured it out, after re-reading the documentation.

    {allBasePage {
        items{
          name (culture:"de"),
          url (culture:"de"),
          contentTypeAlias,
            headline (culture:"de")
        }
      }
    }
    

    so this actually returns all nodes, but "null" for those where a german value is not available. Is there a shortcut to set this globally?

  • Davy Lowyck 8 posts 110 karma points
    Nov 05, 2020 @ 12:24
    Davy Lowyck
    0

    Hi Gerhard,

    Try putting (culture: "de") on items. Like:

    {allBasePage {
        items(culture:"de") {
          name ,
          url ,
          contentTypeAlias,
            headline 
        }
      }
    

    If that doesn't work, put it on allBasePage?

    But still - my own question still stands: is there a GraphQL alternative to the _urls field that exists in the Content Delivery API?

  • Gerhard Grossberger 54 posts 178 karma points
    Nov 05, 2020 @ 12:34
    Gerhard Grossberger
    0

    Thanks, works if I put them here:

      allBasePage(culture:"de") 
    
  • Davy Lowyck 8 posts 110 karma points
    Nov 06, 2020 @ 11:08
    Davy Lowyck
    102

    Found the answer to my own question: "how do I get other language version urls via Heartcore GraphQL?"

    You can supply a culture parameter to the content.url field!

    So to get the urls of the nodes in multiple languages you can do:

    query {
      allContent {
        edges {
          node {
            name,
            url_en: url(culture: "en-US")
            url_fr: url(culture: "fr-FR")
          }
        }
      }
    }
    

    Compared to the _urls field in the content API, here you need to explicitly make a field per language url in your graphql query, but you don't often need to add languages to a setup so I can live with that.

Please Sign in or register to post replies

Write your reply to:

Draft