I am trying to fetch some data from my CMS but I am facinf an error when fetching a specific data. It's an array that I want to fetch with the graphql query :
{
allPrismicLastPosts {
nodes {
data {
links {
blog {
document {
... on PrismicBlog {
data {
post_img {
url
}
post_title {
text
}
post_paragraph {
text
}
tag
}
}
... on PrismicCulture {
data {
tag
culture_image {
url
}
culture_paragraph {
text
}
culture_title {
text
}
}
}
}
}
}
}
}
}
}
This is it JSON Format :
"links": [
{
"blog": {
"document": {
"data": {
"post_img": {
"url": "https://images.prismic.io/zinee/67254822-5c44-42fe-8d5b-7f500141c3a7_Mask%20Group%20(1).png?ixlib=gatsbyFP&auto=compress%2Cformat&fit=max"
},
"post_title": {
"text": "Make more time for the work that matters most using our services"
},
"post_paragraph": {
"text": "A lot of different components that will help you create the perfect look"
},
"tag": "Fiction"
}
}
}
},
{
"blog": {
"document": {
"data": {
"post_img": {
"url": "https://images.prismic.io/zinee/4898e2a8-ebfb-41d4-b843-550e9d9c84da_Mask%20Group.png?ixlib=gatsbyFP&auto=compress%2Cformat&fit=max"
},
"post_title": {
"text": "Make myspace your best designed space"
},
"post_paragraph": {
"text": "A lot of different components that will help you create the perfect look"
},
"tag": "Fiction"
}
}
}
},
{
"blog": {
"document": {
"data": {
"post_img": {
"url": "https://images.prismic.io/zinee/67254822-5c44-42fe-8d5b-7f500141c3a7_Mask%20Group%20(1).png?ixlib=gatsbyFP&auto=compress%2Cformat&fit=max"
},
"post_title": {
"text": "Make more time for the work that matters most using our services"
},
"post_paragraph": {
"text": "A lot of different components that will help you create the perfect look"
},
"tag": "Fiction"
}
}
}
},
{
"blog": {
"document": {
"data": {
"post_img": {
"url": "https://images.prismic.io/zinee/4898e2a8-ebfb-41d4-b843-550e9d9c84da_Mask%20Group.png?ixlib=gatsbyFP&auto=compress%2Cformat&fit=max"
},
"post_title": {
"text": "Make myspace your best designed space"
},
"post_paragraph": {
"text": "A lot of different components that will help you create the perfect look"
},
"tag": "Fiction"
}
}
}
}
]
I get a Cannot read properties of undefined (reading 'text')
error when I fetch it like this :
{post.data.links.map((test)=>
(
<>
<h1>{test.blog.document.data.post_paragraph.text}</h1>
</>
))}
But when I try to fetch like this it works:
{post.data.links.map((test)=>
(
<>
<h1>{test.blog.document.data.tag}</h1>
</>
))}
Any idea how to fix this please ?
the tag
field works and get fetched perfectly but with data like : post_paragraph.text
or title.text
doesn't work !!