Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL draft queries don't return Matrix content #5031

Closed
mattstein opened this issue Oct 2, 2019 · 5 comments

Comments

@mattstein
Copy link
Contributor

commented Oct 2, 2019

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
@mattstein mattstein changed the title GraphQL draft queries return empty Matrix arrays GraphQL draft queries don't return Matrix content Oct 2, 2019
@ca-miked

This comment has been minimized.

Copy link

commented Oct 10, 2019

Having the same issue.

@mortscode

This comment has been minimized.

Copy link

commented Oct 10, 2019

Same issue here as well.

@andris-sevcenko

This comment has been minimized.

Copy link
Member

commented Oct 12, 2019

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

@brandonkelly

This comment has been minimized.

Copy link
Member

commented Oct 12, 2019

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.

@mattstein

This comment has been minimized.

Copy link
Contributor Author

commented Oct 12, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.