Sitecore Community GraphQL Cookbook

Fields - General Link

GraphQL query to demonstrate different ways to retrieve General Link field from Experience Edge
Source:
    CommunityDelivery APIFields

JSON Variables

1{
2  "language": "en",
3  "itemId": "{FE114A34-5A9E-4319-B6DB-A7CC27278F54}"
4}

Query

1query GeneralLinkDemo($itemId: String!, $language: String!) {
2  item(path: $itemId, language: $language) {
3    linkWithJsonValue: field(name: "Link") {
4      jsonValue
5    }
6    linkRawValue: field(name: "Link") {
7      value
8    }
9    linkTyped: field(name: "Link") {
10      ... on LinkField {
11        text
12        anchor
13        target
14        url
15      }
16    }
17  }
18}
19

JSON Response

1{
2  "data": {
3    "item": {
4      "linkWithJsonValue": {
5        "jsonValue": {
6          "value": {
7            "text": "About us",
8            "anchor": "anchor",
9            "linktype": "internal",
10            "class": "",
11            "title": "alt text",
12            "target": "_blank",
13            "querystring": "",
14            "id": "{5BF1A38A-3C0D-4452-9FE7-BC307BE87974}",
15            "href": "/about-us/contact-us"
16          }
17        }
18      },
19      "linkRawValue": {
20        "value": "<link text=\"Aboutus\" anchor=\"anchor\" ... .. id=\"{5B...}\" />"
21      },
22      "linkTyped": {
23        "text": "About us",
24        "anchor": "anchor",
25        "target": "_blank",
26        "url": "/en/about-us/contact-us#anchor"
27      }
28    }
29  }
30}