We are in the process of upgrading our Tridion installation, and in this process we've worked on rewriting various parts of our codebase that is written in C#. We are in the need of some help when it comes to some parts related to your GraphQL API and would therefore like to submit this as an enhancement request. Please let us know if we can clarify our need or if there's anything else you need from us to understand our needs here.
Our need - the problem
We would like to be able to get an entire category's complete keyword structure using a GraphQL request.
What we can see in the GraphQL API is that we can get information about all categories for a given publication with the possibility to extract information about its children aswell. The problem for us is that we are required to specify the level of children in our GraphQL request / query, see example below for a query that would fetch categories with keyword children 1-2 levels down.. This is an issue since we can't ask to get the entire structure. (We could do so in the old in-process api that retrieved published data from the broker using the TaxonomyFactory, see C# code sample below)
This limitation means that if the category structure expands, our query might not get all keywords in the structure. Below is a simple code sample that we had to retrieve the entire category + keyword structure using the old in-process api in C#:
// Getting taxonomyUri (categoryId) for a given keyword TcmId.
var myKeyword = taxonomyFactory.GetTaxonomyKeyword(keywordTcmId);
var categoryId = myKeyword.TaxonomyUri;
// Getting complete keyword structure for this category
var categoryKeywords = taxonomyFactory.GetTaxonomyKeywords(categoryId);
We would like to be able to:
Get an entire category's keyword structure by either passing in a TcmId for a category or keyword or the name/title of a keyword or category using GraphQL api.
Our current workaround in the code
We are generating a query for the GraphQL request that is creating X number of levels in the query so that we get as many child levels as we want. This is not an ideal solution either since the query itself contains much text/content and becomes quite unreadable, and is not a dynamic solution either since it is not aware of whether a category structure has expanded beyond the number of levels that the query had defined.
Sample GraphQL query with X levels of keyword children
As you can see, we're fetching all categories and try to retrieve some info about each category, and then we get its children, and its children, and its children.. We have some categories that have a depth of 5, which gets quite messy in the code. Our biggest concern is that the depth can increase as more keyword children are added, but there's no good solution in place in the GraphQL API that supports our implementation.
query ($namespaceId: Int!, $publicationId: Int!) {
categories(namespaceId: $namespaceId, publicationId: $publicationId) {
edges {
node {
itemId
title
children {
edges {
node {
title
itemId
children {
edges {
node {
itemId
children {
edges {
node {
itemId
}
}
}
}
}
}
}
}
}
}
}
}
}