gatsby-source-strapi icon indicating copy to clipboard operation
gatsby-source-strapi copied to clipboard

`content.data` is null when `lastFetched` exists

Open ohcmadah opened this issue 2 years ago • 8 comments

Hi,

I have a richtext type content field. Everything was good when I build it for the first time without cache. But I modified the post in Strapi and rebuilt it. Then the content.data of the post that I modified was null.

graphql

version

gatsby ^4.7.2 gatsby-source-strapi 2.0.0-beta.0 Strapi 4.1.0

ohcmadah avatar Mar 14 '22 03:03 ohcmadah

@ohcmadah did you published your post or did you do it on a draft one?

soupette avatar Mar 14 '22 09:03 soupette

@soupette The post has already been published. I just saved the post after editing.

ohcmadah avatar Mar 14 '22 10:03 ohcmadah

@soupette We appear to be having the same issue as @ohcmadah

We are working with,

gatsby 4.10.11 gatsby-source-strapi 2.0.0-beta.0 Strapi 4.1.5 Node 14.16.0

I am not sure if what I am seeing is the expected behaviour or not. The side effects of what I am experiencing are causing issues with Gatsby Cloud Builds and Previews.

My test case involved a simple basic page content type with three fields, Title, Body and Image. I added two test pages one published, and the other in draft mode (never been published).

In Gatsby config I'm using the publicationState query params to switch between live and preview modes.

queryParams: { 
	publicationState: process.env.GATSBY_IS_PREVIEW === 'true' ? 'preview' : 'live',
}

My query is as follows,

query MyQuery {
  allStrapiBasicPage {
    edges {
      node {
        id
        Title
        Body {
          data {
            Body
          }
        }
        publishedAt
        Image {
          url
        }
      }
    }
  }
}

Querying with publicationState set to 'live'. I'm getting all field values for just the page that is published. This is what I would expect.

{
  "data": {
    "allStrapiBasicPage": {
      "edges": [
        {
          "node": {
            "id": "16e95dfd-b3cb-56ba-9d2e-039229442088",
            "Title": "Page 1",
            "Body": {
              "data": {
                "Body": "This page has been published."
              }
            },
            "publishedAt": "2022-03-18T15:59:38.312Z",
            "Image": {
              "url": "/uploads/ehteshamul_haque_adit_0_Dg108bwghs_unsplash_b61aadce10.jpg"
            }
          }
        }
      ]
    }
  },
  "extensions": {
    "enableRefresh": "true"
  }
}

Querying with publicationState set to 'preview'. I'm getting both the draft and published page in the results. This all seems normal to me at this stage.

{
  "data": {
    "allStrapiBasicPage": {
      "edges": [
        {
          "node": {
            "id": "16e95dfd-b3cb-56ba-9d2e-039229442088",
            "Title": "Page 1",
            "Body": {
              "data": {
                "Body": "This page has been published."
              }
            },
            "publishedAt": "2022-03-18T15:59:38.312Z",
            "Image": {
              "url": "/uploads/ehteshamul_haque_adit_0_Dg108bwghs_unsplash_b61aadce10.jpg"
            }
          }
        },
        {
          "node": {
            "id": "b05334a3-ebfc-54b5-9b90-7ab7d0b5dae9",
            "Title": "Page 2",
            "Body": {
              "data": {
                "Body": "This page is unpublished so therefore in Draft mode."
              }
            },
            "publishedAt": null,
            "Image": {
              "url": "/uploads/ehteshamul_haque_adit_0_Dg108bwghs_unsplash_b61aadce10.jpg"
            }
          }
        }
      ]
    }
  },
  "extensions": {
    "enableRefresh": "true"
  }
}

So now I go into Strapi and edit any field in Page 1 (the published content) and hit save. Refreshing Data in GraphiQL yields a different result which I do not full understand.

The field values for the published page (page 1) appear fine apart from the rich text 'Body' field which is now null. This does not seem like the expected behaviour to me.

{
  "data": {
    "allStrapiBasicPage": {
      "edges": [
        {
          "node": {
            "id": "b05334a3-ebfc-54b5-9b90-7ab7d0b5dae9",
            "Title": "Page 2",
            "Body": {
              "data": {
                "Body": "This page is unpublished so therefore in Draft mode."
              }
            },
            "publishedAt": null,
            "Image": {
              "url": "/uploads/ehteshamul_haque_adit_0_Dg108bwghs_unsplash_b61aadce10.jpg"
            }
          }
        },
        {
          "node": {
            "id": "16e95dfd-b3cb-56ba-9d2e-039229442088",
            "Title": "Page 1",
            "Body": {
              "data": null
            },
            "publishedAt": "2022-03-18T15:59:38.312Z",
            "Image": {
              "url": "/uploads/ehteshamul_haque_adit_0_Dg108bwghs_unsplash_b61aadce10.jpg"
            }
          }
        }
      ]
    }
  },
  "extensions": {
    "enableRefresh": "true"
  }
}

The only way to get the value of Body back is to do a clean rebuild with Gatsby.

pixeldust avatar Mar 21 '22 11:03 pixeldust

Can confirm this. Having the same issues.

  • gatsby 4.13
  • gatsby-source-strapi 2.0.0
  • gatsby-plugin-gatsby-cloud 4.14.0-next.3
  • Strapi 4.1.9
  • Node 14.16.0

I have a heroku strapi-deploy and gatsby through their cloud. I'd like to add the following observation;

My posts have various fields (richtexts, shorttexts, number arrays and so on) and components (dynamic repeatable zone) and the publishing process to first preview your content changes through the gatsby-cloud plugin work fine. Even if I do incremental cloud builds without cache it works. I can change images, rearrange orders and so on. All none RichText fields from strapi are working fine basically, I tested them all. Builds and previews are complete and fast and built without cache.

But as soon as I change any RichText content, the preview and build fails. Only after a fresh cache build it'll show the content. So i think it only has to do with RichText fields (data.childMarkdownRemark.html) and returning null after updating and therefore break the build since gatsby-source-strapi works as intended here I guess.

Any ideas? Did someone find a way to get around this?

... on STRAPI__COMPONENT_SHARED_RICH_TEXT {
    richTextBody: body {
        __typename
        data {
          id
          childMarkdownRemark {
            html
          }
        }
      }
    }

youmeokay avatar May 02 '22 17:05 youmeokay

We have the same issue! Is there any workaround for this? It is very urgent, because I do not know any way for my customers to get their content online without deleting the cache and bearing very long build time.

kjoscha avatar Jun 20 '22 19:06 kjoscha

I fixed all my problems with this source plugin: https://github.com/relate-app/gatsby-source-strapi It can do incremental builds and previews (which was important to me).

youmeokay avatar Jun 20 '22 20:06 youmeokay

Has anyone found a solution for this? I'm having the same problem

joanargarrido avatar Jul 28 '22 16:07 joanargarrido

@joanargarrido see #321

MRDRMUFN avatar Aug 06 '22 22:08 MRDRMUFN

Can confirm I have the same issue currently

MotaZor94 avatar Nov 08 '22 11:11 MotaZor94