rich-text
rich-text copied to clipboard
Query returns nothing for embedded-asset-block type nodes.
Hello, team. I have an ApolloClient with the uri of https://graphql.contentful.com/content/v1/spaces/${SPACE}/environments/master?access_token=${TOKEN}
to make queries using the useQuery
hooks from @apollo/client
.
Unfortunately, when I have a query that expects an embedded-asset-block
, I don't get anything in return. I have a rich body that has some embedded assets like images and videos. The textual data (h1, p) - those are returning fine but the embedded types return nothing. I need the embedded types because I am using documentToReactComponents
from @contentful/rich-text-react-renderer
to render the rich body in its entirety.
Here is the query:
{
newsEntryCollection(where: {slug: $slug}) {
items {
body {
json
}
imagesCollection {
items {
url
contentType
}
}
}
}
}
Returns
{
"data": {
"newsEntryCollection": {
"items": [
{
"body": {
"json": {
"nodeType": "document",
"data": {},
"content": [
{
"nodeType": "paragraph",
"content": [
{
"nodeType": "text",
"value": "We’re living through so much these days, that at times it feels like attending to our basic needs is plenty. And while that means being gentle with ourselves, it doesn’t mean we have to give up on our ‘best selves’ entirely. But instead of forcing your way through another push-up competition or zoom book club, it’s nice to remember that sometimes doing less really is more.",
"marks": [],
"data": {}
}
],
"data": {}
},
{
"nodeType": "embedded-asset-block",
"content": [],
"data": {
"target": {
"sys": {
"id": "1naXSnyhKwtvVIGk2GGzer",
"type": "Link",
"linkType": "Asset"
}
}
}
},
You can find solutions at #119
#119 has no answer whatsoever. This remains unsolved.
The same issue occurs with a Gatsby setup and embedded-entry-block
Same with nextjs and querying with graphql. Will this be solved or we switch back to sdk? Thanks.
Any update on this?
Have same issue. embedded-asset and embedded-entry have no content.
Is this still open?
still not solved nextjs v13
I'm unsure whether this fix will work for anyone else, but I changed my GraphQL query to fetch the right data and it fixed my issues... In my GraphQL query, I only requested the json
property of the resource, but the URL for the image and other assets is under links
.
The links
content doesn't show up on Contentful's JSON viewer, so it took poking around in the GraphQL playground to realize that it was there.
BEFORE (here I wasn't getting all the data I needed)
myResource {
json
}
FIXED:
myResource {
json
links {
assets {
block {
title
description
fileName
contentType
url
}
}
}
}