XM Cloud - All about XM Preview and Edge GraphQL

 I have recently started working on the xmcloud project to fetch the data from xmcloud using GraphQL, I have faced some challenges using GraphQL in both the XM preview and EDGE environment.

I am sharing details that will help others who like to use GraphQL extensively for querying and searching content from xmcloud.

Challenges:

  • Need to access the item from the data folder which is not under the home node.
    • I have written the GraphQL Item query to fetch the datasource item under the data folder.
    • The response is fine in the XM preview environment with all the data from different fields like image,droplink,droptree,treelist, and treelistex, etc coming properly,  but when switched to EDGE the query does not work as expected, it provides the response in raw values.
    • The reason behind showing raw value is that the items under the data folder do not have any site definition to them and it does have a presentation.


  • If anyone faced this issue, then you will be happy now with the latest release of XM Cloud released. As of now EDGE raw value issue is resolved. We will able to update to this latest release by just triggering build and release from XM Cloud deploy application.


  •     Retreive the item from Sitecore using DateTime:
    • When I tried to use the Search GraphQL query to filter the results by date, I'm not getting any results as XM Preview and EDGE handles date filtering in different ways.
    • XM Preview Date filtration:

    • XM Preview Date Filtration Solution:
      • But in XM Preview we need to exactly pass the date value with the timestamp then only we can be able to retrieve the results.
      • To retrieve jsonValue we can retrieve a field  like below
        • PublishDate: field(name: "PublishDate") {        jsonValue      }
      • Only the EQ operator works for filtering results
    • EDGE Date Filtering Issue.
    • I have used the same query in EDGE but no it returns no results.
    • EDGE Data Solution
      • For EDGE, date filtration will be done by value instead of jsonValue
        • PublishDate: field(name: "PublishDate") { value }      
      • We can pass with and without timestamps for filtration
      • We can pass either EQ or CONTAINS operator
      • Note: Both XM Preview and Edge at present do not support date range filtration. it will be added in the upcoming release.
    • Pagination for the search results:
      • Setup up pagination:
      • Pagination is based on the total, hasNext, and endCursor property values from the search response.
        • Pagination works well in both XM Preview and EDGE.
        • Now I have updated the query to add a sorting condition and it works well in XM Preview, so I have tried to implement the same in EDGE and it not works.
      • In EDGE I have passed the endCursor value to the after property based on the hasNext and total value from the response, but instead of giving the pagination data, it returns again the same search results. 
      • Note: At present, orderBy with pagination in the Search GraphQL query is not supported by EDGE. Sitecore support team looking into it, I will update here if this feature is supported.
    • Filtering the item based on Treelist/Droplink, Multilist, etc:
      • When I try to filter the items using the Search query, I couldn't get the expected results, as filtration does not work with GUID, as we need to filter the results based on the raw value for these fields.
      • It is now fixed and we can able to retrieve the results using GUID for filtering the results.
    • Multiple Where condition with AND and OR:
      • Multiple where condition to filter the results works fine with XM Preview.
      • When I tried to use the same multiple where conditions query with EDGE it fails, I found this issue is caused when we pass the search parameter for the filtration as variables. but if we pass parameter values directly like the below screenshot it works.

I hope this information will help and big thanks to the Sitecore support team.

Happy programming 😊


Comments

Popular posts from this blog

Custom Item Url and resolving the item in Sitecore - Buckets

Sitecore Custom Rule (Action and Condition)