2

I have a template with a droplink "productarea". When I use a GraphQL to fetch this item, the value of the "productarea" is a GUID. This guid points to an item in the sitecore tree, and I need the displayName of that item. Is this possible to get using a single GraphQL, or do I need to run a second GraphQL from the client?

Here are the queries I'm using:

query getArticles($item: String = "{02E9F5E2-8CDE-4A52-B260-62B628692BF8}") {
  item(path: $item) {
    ...articleFields
  }
}

fragment articleFields on ArticlePage {
  productarea{
    value
  }
}

query getArea($item: String = "{ADAA9D5C-4C30-477B-960A-0062B384F235}") {
  item(path: $item) {
    displayName
  }
}

Get articles result:

{
  "data": {
    "item": {
      "productarea": {
        "value": "{ADAA9D5C-4C30-477B-960A-0062B384F235}"
      }
    }
  }
}

GetArea result

{
  "data": {
    "item": {
      "displayName": "Doors"
    }
  }
}
2

Yes you can resolve a Sitecore Droplink to an Item in one query, a Droplink has a targetItem that is the way to access the fields of the reference in GraphQL.

GraphQL Example:

query getArticles($item: String = "{02E9F5E2-8CDE-4A52-B260-62B628692BF8}") {
  item(path: $item) {
    ...articleFields
  }
}

fragment articleFields on ArticlePage {
  productarea{
    value
    targetItem {
      displayName
   }
  }

Where productarea is a Droplink field on template ArticlePage and the provided GUID {02E9F5E2-8CDE-4A52-B260-62B628692BF8} is the ArticlePage Item from the content tree.

  • That worked like a charm, thank you ever so much – devzero Oct 7 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.