Fetch nested quert react

I have an issue when I fetch data from my cms. I get certain data but when I am trying to get nested data I don’t know how to correctly write my query. my CMS looks like this:

I am trying to fetch the data that is underneath widgets. When I expand widgets it looks like this:

I am trying to fetch the Widget ID and the Heading. my query looks like this foe now:

export const QUERY = (): string => {
    return `query Overview {
        overview { 
            customer
            introText
            title
            totalScore {
                widgetId
                heading
                description
            }
            totalScoreComparison {
                heading
                description
                widgets #Here is my issue, how do I write this to get the widget id and the heading? 
            }
            dimensionWeight {
                heading
                description
                widgets 
            }
            introOverlay {
                heading
                description
                image {
                    url
                  }
            }
         }
      }`;
};

The data. that I get out is this:


My widgets are empty. I can’t get the widget Id - feels like I have tried everything, how do I write the correct query to get my widget id and my heading?

Hello @nicole.lopez

The query to access these fields inside the block would be:

query MyQuery {
  overview {
    customer
    introText
    title
    totalScore {
      widgetId
      heading
      description
    }
    totalScoreComparison {
      heading
      description
      widgets {
        ... on WidgetHeadingRecord { #name of the block the fields are in
          heading
          widgetId
        }
      }
    }
    dimensionWeight {
      heading
      description
      widgets {
        ... on WidgetHeadingRecord { #name of the block the fields are in
          heading
          widgetId
        }
      }
    }
    introOverlay {
      heading
      description
      image {
        url
      }
    }
  }
}

In the “API Explorer” tab, you can get an intuitive UI that will build a query for you based on the fields and blocks you want to get

1 Like

Thank you so much! This worked for me!