More GraphQL Query Example In Sitecore JSS

Hello everyone. In this blog we will see more example of writing GraphQL queries. This is continue part of my previous blog which you can find here

So let's start without wasting any extra time. Below is the Sitecore structure which we will be using in our case.

Let me give you an overview. We are having going to read children of Social Links folder. There are links item created from two different template. One is Social Link and another one is Footer Link. This is just for example purpose. Social Link template has one Image field named as logo. Below is the screenshot for your reference.

Reading Children of Item passed as query parameter in GraphQL

If you see above query, we are passing datasource and language as Paramter. Then we are calling children which is responsible for getting all Sitecore items under result object.We are just showing the template name and item name from the result

Reading Children of of Item passed as Query in GraphQL with template id filter

If you see we are passing one paramter to Children that is includeTemplateIDs : ["{template id}"] and it get result for those items only

Reading Children of of Item passed as query paramtere in GraphQL with template type safe.

If we think in practical,this type of logic can be used when we are having multiple items as children with different template type. Also those two items as image field with different name(logo - Social Link template and image - Footer Link template) and we have two read those image field. So when using type safe we can pass the exact field name from the respective template to get the values.Below is the screenshot for your reference.

In the above query, you might be wondering what is ...ImageQuery. Let me explain, that is fragmentation concept in GraphQL. When we are having similar field structure which is going to be use at multiple places, then separate it out using fragment.

Reading Multilevel Children of of Item passed as query parameter in GraphQL with template type safe.

There is one more property which can be used with when we are reading field in GraphQL and that is jsonValue.It return all the members of that field in JSON format.

Hope this blog will help you. Happy learning!! Happy Sitecoring!!

You can check my other blogs blog related to Sitecore

Comments

Popular posts from this blog

Sitecore XM Cloud Form Integration with Azure Function as Webhook

Automate RSS Feed to Sitecore XM Cloud: Logic App, Next.js API & Authoring API Integration

Create and Fetch Content From Sitecore Content Hub One using GraphQL and React