5

I am trying to fetch the dropTree field vlaue of assigned datasource item in one of my headless Projects.

Have written the below query but here I'm getting dropTree seleted item now i want seleted item details.

GraphQL Query -

query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") 
    id
    name
    ... on HistoryDetails {
      dropTreeFIeld {
        id
        name
        targetItem {
          id
          name
        //  here i'm getting dropTree seleted item now i want seleted item details.
          }
        }
      }
    }
  }
}

Has anyone had this problem or know how to fix it?

5 Answers 5

2

To retrieve details of the selected item in the dropTree, adjust your query to match the structure of the HistoryDetailsItems template. If you need specific field values from this template, modify your query to target those fields directly.

query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") {
    id
    name
    ... on HistoryDetails {
      dropTreeFIeld {
        id
        name
        targetItem {
          id
          name
          ... on HistoryDetailsItems {
             #you can replace title or description with your template fields
            title {
              value
            }
            description {
              value
            }
          }
        }
      }
    }
  }
}

In this case, HistoryDetailsItems refers to the template of the item chosen in the droptree field. title and description represents a specific field within that template. You can include additional fields from the same template using this format.

Hope this helps!!!

3

To get info about Targetitem from the droptree field, use this GraphQL query:

query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") 
    id
    name
    ... on HistoryDetails {
      dropTreeFIeld {
        id
        name
        targetItem {
          id
          name
          ... on YourTemplateName{
             YourTemplatefieldName{
               value
             }
           }
          }
        }
      }
    }
  }
}

In this case, YourTemplateName is the name of the template for the item you picked from the dropdown list.YourTemplatefieldName is one of the fields in that template . You can add more fields from the template in the same way.

2

You can use the below query to get the droptree field values

 query Droptree($datasource: String!) {
      datasource: item(path: $datasource, language: "en") 
        id
        name
        ... on Campus {
          dropTreeField {
            id
            name
            targetItem {
              id
              name
            fields {
                title {
                  value
                }
                description {
                  value
                }
            }
          }
        }
      }
    }

Where Title , Description are your field names you can use your field name

0

In order to retrieve details of Targetitem on the droptree field, you can run below GraphQL query.

query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") 
    id
    name
    ... on HistoryDetails {
      dropTreeFIeld {
        id
        name
        targetItem {
          id
          name
          ... on TargetItemTemplateName{
             fieldName{
               value
             }
           }
          }
        }
      }
    }
  }
}

In the above example, TargetItemTemplateName is the template name of the item selected on the droptree field and fieldName is one of the fields in the TargetItemTemplateName. Similarly you can add more fields of the template in the same format.

Hope this helps!!! Let me know in case you face any issues.

0

You can use the below modified query:

    query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") 
    id
    name
    ... on HistoryDetails {
      dropTreeFIeld {
        id
        name
        targetItem {
          id
          name
        Fields{
            jsonValue
           }
          }
        }
      }
    }
  }
}

OR

query ContentCardQuery($datasource: String!) {
  datasource: item(path: $datasource, language: "en") 
    id
    name
    ... on HistoryDetails {
      dropTreeFIeld {
        jsonValue 
        }
      }
    }
  }
}

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.