2

I have an item in sitecore which has a field with Specialized Treelist selection. I want to query this field using GraphQL query.

Query:

{
  item(path: "{98414240-69F7-4768-9B22-FE8EF17BE984}") {
    id
    path
    __typename
    
    field(name: "Navigation Links") {
      id
      name
      value
      __typename
      
      definition {
        type
        section
      }
    }
  }
}

GraphQL Response:

{
  "data": {
    "item": {
      "id": "9841424069F747688B22FE8EF17BE844",
      "path": "/sitecore/content/AppName/Global/Configuration/Navigation/ItemName",
      "__typename": "LatestItems",
      "field": {
        "id": "C5533E0966FA4E00B392FAAC1371DA06",
        "name": "Navigation Links",
        "value": "{F533B0DB-085F-4FF5-BA35-D35E070D2210}|{2F23DDA3-EC80-47C8-87ZB-8F23598A08F3}|{EF9E7614-3D42-40A8-AFDD-47B0C62CE506}|{2F0E3536-0ABC-433A-8B4C-E1817E29298C}|{E8BCE000-08C9-4361-9D66-5FBA502C35F0}|{14A19584-E559-4449-9F42-6FD16FCC23E9}|{6511E9E0-DF97-478E-BBE8-2F1833B89BFE}|{3D5541DF-2891-4D88-ACD5-ECFB79A3C5A5}|{D3AD6307-F7E0-4951-3232-6A44E8C99ABF}|{898C8997-16C2-4B0E-B87F-49E09DCCB553}",
        "__typename": "TextField",
        "definition": {
          "type": "Specialized Treelist",
          "section": "Content"
        }
      }
    }
  }
}

I want the pipe separated values to show the details of item e.g title, displayName, fields etc.

Any help would be appreciated. Thanks!

2 Answers 2

3

Solved it by adding the mapping for Specialized TreeList in the graphql content config.

Config Path: inetpub\wwwroot\sitename\Website\App_Config\Sitecore\Services.GraphQL\Sitecore.Services.GraphQL.Content.config

Append below line:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
    <sitecore>
        <api>
            <GraphQL>
                <!-- the defaults section contains config templates that can be reused elsewhere using 'ref' -->
                <defaults>
                    <content>
                        <fieldTypeMappings>
                            <standardTypeMapping type="Sitecore.Services.GraphQL.Content.TemplateGeneration.FieldTypeToGraphQLTypeMapper, Sitecore.Services.GraphQL.Content">
                                <typeMapping hint="raw:AddTypeMapping">

                                    <map field="Specialized Treelist" type="Sitecore.Services.GraphQL.Content.TemplateGeneration.FieldMapping.MultilistFieldTypeFactory, Sitecore.Services.GraphQL.Content" />

                                </typeMapping>
                            </standardTypeMapping>
                        </fieldTypeMappings>
                    </content>
                </defaults>
            </GraphQL>
        </api>
    </sitecore>
</configuration>

0

You can get items from the list by using the targetItems. by using a inline fragment you can cast the field to a List. The query looks like somethings like this:

 {
  item(path: "{98414240-69F7-4768-9B22-FE8EF17BE984}") {
    id
    path
    __typename
    
    field(name: "Navigation Links") {
      id
      name
      value
      ...NavLinks
      __typename
      
      definition {
        type
        section
      }
    }
  }
  
  fragment NavLinks on MultilistField {
    navlink: targetItems {
     name
     id
     field(name: "title") {
      mytitle: value
     }
    }
}
3
  • Hi Jan, thanks for the suggestion. The problem is that "Navigation Links" type is shown as TextField by GraphQL in the response I mentioned in the question. Thats why the above NavLinks fragment does not work. It does not have any impact on the response.
    – Ajit Singh
    Oct 13, 2020 at 9:18
  • I feel that GraphQL is not able to understand the "Specialized Treelist" type hence it converts it into TextField. Thoughts?
    – Ajit Singh
    Oct 13, 2020 at 9:42
  • yep that make sense, custom field, looks like not able to cast Oct 13, 2020 at 12:43

Your Answer

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

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