Hi All,
We are looking at moving from the assets API to using GraphQL. One of the things we have noticed is that we can't get the ordering of content fragments within a folder back from the GraphQL.
Ordering is important to us. Does anyone have any advice on how to pull the ordering of Content Fragments back through GraphQL or in another simple API call without having to traverse the structure to build it up?
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
@AEM_PARTY You might have to rethink over strategy. I can still see following ways:
A. If they belong to same CFM, then consider 2nd option in my above comment - Add a field in the CFM, which would increment or indicate the order of its creation in a folder. And base your Sorting Order in Graphql Query with that Field.
B. Query Hybrid, get all the CFs in a folder via Asset HTTP API, to maintain the natural order. Iterate over the response and trigger Graphql Query with CF Path fetched from Asset HTTP API.
Please note for Option B, you might have to scalability and performance issues, for increasing number of CFs in a folder.
Please check this example of sorting in GraphQL Query
Thanks for that but what I need to know is the order of the Content Fragments in the folder.
I can't see a way to get this out of GraphQL whereas the assets API gives you the Content Fragments in order.
When you query(GraphQL API) a particular folder without any filtering/sorting in the query, does it give the results item in random fashion than what is order stored in JCR?
What happens is you need to query for all CFMs.
From there, you form a query for all the CFs of all those CFMs.
The CFs come back and contain their path but there is nothing to indicate the order they are in the folder.
This order in the folder is what determines the site structure.
This is a such a shame as well as if GraphQL could work it would reduce the grab time from 2 minutes to 1 second!
Hi @AEM_PARTY
Please check the below link which says that by default sorting criteria is repository path:
By default it uses the repository path of each item of the result set to make sure the order is always the same
https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap...
Hence, if the ask is to get the CFs in order they were added to a folder, I can think of two ways:
1. Either follow the naming of CFs as such that they are fetched as per their naming order. In this case you might not have to define sorting order explicitly
2. Add a field in the CFM, which would increment or indicate the order of its creation in a folder. And base your Sorting Order in Graphql Query with that Field
Hope this helps.
Thanks for the pointers but sadly these don't work.
For example I have a folder:
You can see I can't infer an order form the names. Also, the order the CFs are entered in is not useful either as I may create another Content Fragment say, "Environment" and I want that to slot in above "Contact".
@AEM_PARTY You might have to rethink over strategy. I can still see following ways:
A. If they belong to same CFM, then consider 2nd option in my above comment - Add a field in the CFM, which would increment or indicate the order of its creation in a folder. And base your Sorting Order in Graphql Query with that Field.
B. Query Hybrid, get all the CFs in a folder via Asset HTTP API, to maintain the natural order. Iterate over the response and trigger Graphql Query with CF Path fetched from Asset HTTP API.
Please note for Option B, you might have to scalability and performance issues, for increasing number of CFs in a folder.
What you can do is to create a "root" CF Model that includes a fragment reference multifield. There, you can add references to all fragments you want to list, and the multifield allows you to reorder them manually.
Of course this is a pain if you handle many CFs, but might solve your problem if you handle a few CFs.
It's a shame GraphQL doesn't follow the order of the CFs in the folder which can be reordered from the list view.