rich-text icon indicating copy to clipboard operation
rich-text copied to clipboard

Query returns nothing for embedded-asset-block type nodes.

Open icncsx opened this issue 4 years ago • 9 comments

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"
                      }
                    }
                  }
                },

icncsx avatar Nov 16 '20 18:11 icncsx

You can find solutions at #119

tomonari-t avatar Nov 26 '20 04:11 tomonari-t

#119 has no answer whatsoever. This remains unsolved.

angelod1as avatar Nov 27 '20 00:11 angelod1as

The same issue occurs with a Gatsby setup and embedded-entry-block

danoszz avatar Dec 01 '20 21:12 danoszz

Same with nextjs and querying with graphql. Will this be solved or we switch back to sdk? Thanks.

foxieManel avatar Dec 07 '20 18:12 foxieManel

Any update on this?

dnobbe1 avatar Feb 20 '21 21:02 dnobbe1

Have same issue. embedded-asset and embedded-entry have no content.

Kyoss79 avatar Feb 24 '21 14:02 Kyoss79

Is this still open?

iahujaklick avatar Apr 02 '23 17:04 iahujaklick

still not solved nextjs v13

tomfraczek avatar Nov 15 '23 12:11 tomfraczek

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
        }
      }
    }
  }

rioredwards avatar Jan 19 '24 05:01 rioredwards