1

Is there a graqhql CD query to get all the keywords inside a category in Taxonomy.

I see an endpoint, but it doesn't serve my purpose: keyword(namespaceId: Int!, publicationId: Int!, categoryId: Int!, keywordId: Int!, contextData: [InputClaimValue]):

Currently I am saving the key/value pairs in client application. so instead of saving in the client application.

I would like to query it using GraphQL Public Content API.

2
  • Arjun , Can you share which version of tridon you are using
    – Anand N S
    Commented Dec 11, 2023 at 12:48
  • I am using version 9.6
    – Arjun
    Commented Dec 12, 2023 at 15:23

1 Answer 1

1

We can get the category and keywords list using GraphiQL APIs in many ways.

Option 1: This approach retrieves all categories and keywords in a single query, providing a comprehensive view of the taxonomy hierarchy. However, be cautious about the potential performance impact, especially in environments with a large number of categories and keywords.

{
  categories(namespaceId: 1, publicationId: 10) {
    edges {
      node {
        id
        itemType
        itemId
        description
        key
        title
        totalRelatedItems
        children {
          edges {
            node {
              ...KeywordFieldsLevel1
              children {
                edges {
                  node {
                    ...KeywordFieldsLevel1
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

fragment KeywordFieldsLevel2 on Keyword {
  title
  description
  itemId
  key
  hasChildren
}

fragment KeywordFieldsLevel1 on Keyword {
  title
  key
  description
  hasChildren
  itemId
  children {
    edges {
      node {
        ...KeywordFieldsLevel2
      }
    }
  }
}

Option 2: The advantage of using this approach it is more targeted, allowing you to fetch specific categories and their first-level keywords individually. This can improve performance when you only need information about a subset of the taxonomy.

query GetCountryKeywords {
  k1: keyword(namespaceId: 1, publicationId: 10, categoryId: 46, keywordId: 1066) {
    ...ParentKeyword
  }
  k2: keyword(namespaceId: 1, publicationId: 10, categoryId: 46, keywordId: 2430) {
    ...ParentKeyword
  }
  k3: keyword(namespaceId: 1, publicationId: 10, categoryId: 46, keywordId: 2433) {
    ...ParentKeyword
  }
  k4: keyword(namespaceId: 1, publicationId: 10, categoryId: 46, keywordId: 2446) {
    ...ParentKeyword
  }
  k5: keyword(namespaceId: 1, publicationId: 10, categoryId: 46, keywordId: 2449) {
    ...ParentKeyword
  }
}

fragment ParentKeyword on Keyword {
  id
  itemType
  itemId
  description
  key
  title
  hasChildren
  children {
    edges {
      node {
        ...KeywordFieldsLevel1
        children {
          edges {
            node {
              ...KeywordFieldsLevel1
            }
          }
        }
      }
    }
  }
}

fragment KeywordFieldsLevel2 on Keyword {
  title
  description
  itemId
  key
  hasChildren
  customMetas {
    edges {
      node {
        key
        value
      }
    }
  }
}

fragment KeywordFieldsLevel1 on Keyword {
  title
  key
  description
  hasChildren
  itemId
  children {
    edges {
      node {
        ...KeywordFieldsLevel2
      }
    }
  }
  customMetas {
    edges {
      node {
        key
        value
      }
    }
  }
}

I hope it helps.

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.