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 Answers 2

3

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.

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

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

query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") {
    id
    name
    ... on InfoDetailComponent {
      droplinkField {
        id
        name
        targetItem {
          id
          name
          ... on DroplinkFieldDetails {
            title {
              value
            }
          }
        }
      }
    }
  }
}
1
  • Hi Praveen, Please add the code in place of the image with your answer for SEO purposes. Thanks Commented Apr 16 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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