1

I want to fetch multiple item data using single query. I am able to fetch the data of single item. My tree structure is like: Item1: Title Description Item2: Title Description Image

I want to get Field like Title,Description from Item-1 and Image from Item-2 in a single graphQL query for sitecore jss. can anyone help me into this? Thanks in advance.

2

You can easily add extra items to a query. give them a unique name for example:

{
  item1: item(path:"/sitecore") {
    id
    name
  }
  item2: item(path:"/sitecore/content") {
    id
    path
    displayName
  }
}

This Query get 2 items by path and and calls them item1 and item2. See also Starting with Sitecore JSS Integrated GraphQL and Sitecore JSS Integrated GraphQL Queries

You need custom fields so handy to use strongly typed. here an example:

{
  item1: item(path:"/sitecore") {
    ...on Root {
      id
    }
  }
  item2: item(path:"/sitecore/content/Home") {
    ...on SampleItem {
        title {
          value
        } 
        text {
         value
      }
    }
  }
}

This should be the result on a fresh install:

{
  "data": {
    "item1": {
      "id": "11111111111111111111111111111111"
    },
    "item2": {
      "title": {
        "value": "Sitecore Experience Platform"
      },
      "text": {
        "value": "<p style=\"line-height: 22px;\">From a single connected platform that also integrates with other customer-facing platforms, to a single view of the customer in a big data marketing repository, to completely eliminating much of the complexity that has previously held marketers back, the latest version of Sitecore makes customer experience highly achievable. Learn how the latest version of Sitecore gives marketers the complete data, integrated tools, and automation capabilities to engage customers throughout an iterative lifecycle &ndash; the technology foundation absolutely necessary to win customers for life.</p>\n<p>For further information, please go to the <a href=\"https://doc.sitecore.net/\" target=\"_blank\" title=\"Sitecore Documentation site\">Sitecore Documentation site</a></p>\r"
      }
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.