user74843
user74843

Reputation: 701

graphQL: how to get an object from a list of objects, in a query

I am trying to use graphQL in a GatsbyJS project, and am unsure how I can pull a specific 'URL' object, from a list of three, within a 'recipeImages' object. Right now, I can only pull the recipeImages object, like this:

<img src={node.recipeImages}/>

but I want to be able to get to the three individual URL objects seen in this query:

{
  "data": {
    "allContentfulBlogPost": {
      "edges": [
        {
          "node": {
            "id": "c1Qz3hWuPuQEIIUkSos0MEO",
            "postTitle": "Schwarzwälder Kirschtorte",
            "postDate": "2018-01-30T00:00+01:00",
            "slug": "schwarzwälder-kirschtorte",
            "methodText": {
              "childMarkdownRemark": {
                "html": "<p>This is the method text</p>"
              }
            },
            "recipeImages": [
              {
                "title": "imageOne",
                "file": {
                  "url": "//images.contentful.com/62o0h4ehxjxr/kkc57vWLPaEakYueyYqC6/c61b4641797a2fcaf3476ef9a3a24db6/image.jpg"
                }
              },
              {
                "title": "imageTwo",
                "file": {
                  "url": "//images.contentful.com/62o0h4ehxjxr/2ifxQEvnYwkaAe6e2YKISa/de2b6f62c4cac3b501fe76146b745790/image1.jpg"
                }
              },
              {
                "title": "imageThree",
                "file": {
                  "url": "//images.contentful.com/62o0h4ehxjxr/17g7ZHqrEWIgcyuye08myG/6b55386a31db2dd319148795953da7a4/image2.jpg"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Upvotes: 1

Views: 529

Answers (1)

user74843
user74843

Reputation: 701

i got it:

<img src={recipeImages[0].responsiveResolution.src}/> 

Upvotes: 1

Related Questions