Cms: GraphQL draft queries don't return Matrix content

Created on 2 Oct 2019  Â·  6Comments  Â·  Source: craftcms/cms

Description

When using Gatsby as a Live Preview target, Matrix blocks completely disappear. Plain Text fields, however, return draft content as expected. This is only true of draft content, as previewing the current version of an entry works as expected.

I also don't think this has to do with Gatsby, as I can reproduce the behavior querying Craft's GraphQL endpoint directly.

Eager loading behind the scenes, perhaps?

Example

query (fragment makes no difference)

{
  home: entries(section: ["homepage"], limit: 1) {
    ... on homepage_homepage_Entry {
      title
      metaDescription
      pageBlocks {
        ...PageBlocks
      }
    }
  } 
}

fragment PageBlocks on pageBlocks_MatrixField {
  ... on pageBlocks_hugeIntro_BlockType {
    typeHandle
  }
  ... on pageBlocks_serviceSummary_BlockType {
    typeHandle
  }
  ... on pageBlocks_statementCta_BlockType {
    typeHandle
  }
  ... on pageBlocks_quote_BlockType {
    typeHandle
  }
}

example.dev/api
response:

{
  "data": {
    "home": [
      {
        "title": "Home",
        "metaDescription": "Web design and development consultancy that plans, designs and builds custom Craft CMS projects and plugins.",
        "pageBlocks": [
          {
            "typeHandle": "hugeIntro"
          },
          {
            "typeHandle": "serviceSummary"
          },
          {
            "typeHandle": "serviceSummary"
          },
          {
            "typeHandle": "serviceSummary"
          },
          {
            "typeHandle": "statementCta"
          },
          {
            "typeHandle": "quote"
          }
        ]
      }
    ]
  }
}

example.dev/api?token=blahblah
response:

{
  "data": {
    "home": [
      {
        "title": "Home",
        "metaDescription": "Here's a silly draft meta description.",
        "pageBlocks": []
      }
    ]
  }
}

Steps to reproduce

  1. Establish and query a GraphQL endpoint for an Entry that contains a Plain Text field with content and populated Matrix blocks. (example: https://foo.dev/api)
  2. Save a Draft of that Entry, changing the Plain Text content and optionally the Matrix blocks.
  3. Perform a second query, passing a valid preview token as a GET parameter. (example: https://foo.dev/api?token=••••••)

Observe that the query response contains the updated Plain Text field value, but that the Matrix block array is empty.

Additional info

  • Craft version: 3.3.6
  • PHP version: 7.3.9
  • Database driver & version: MySQL 5.5.5

Most helpful comment

Just fixed this for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#40d20b6d4ccebc87e7a6dd00f7e0215943db7cf7 as 3.3.9",
  "...": "..."
}

Then run composer update.

All 6 comments

Having the same issue.

Same issue here as well.

Definitely a side-effect of eager loading all the things.

Just fixed this for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#40d20b6d4ccebc87e7a6dd00f7e0215943db7cf7 as 3.3.9",
  "...": "..."
}

Then run composer update.

I can confirm this fixes the problem. Thrilled to use Live Preview for a Gatsby project!

Frickyessss!!!! Thanks @brandonkelly

Was this page helpful?
0 / 5 - 0 ratings