Skip to content

fix(graphql): block editor field for urlcontentmap is a json string instead of an object #31921 #32272

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

valentinogiardino
Copy link
Contributor

@valentinogiardino valentinogiardino commented May 29, 2025

Proposed Changes

  • Ensured that fields ending in _raw are parsed as JSON and injected as objects under their corresponding base key (e.g., blockEditor) — only when that base key already exists.
  • Extracted parsing logic into a private method: enrichWithParsedRawFields.
  • Added an integration test suite (ContentMapDataFetcherTest) that covers:
    • Correct parsing and replacement of blockEditor when blockEditor_raw is present.
    • Ensuring that fields like customField_raw do not inject customField if the base key was not defined.

Checklist

  • Tests
  • Translations
  • Security Implications Contemplated (no sensitive processing; only structural parsing of contentlet fields)

Additional Info

Fixes the issue where GraphQL was returning blockEditor as a raw JSON string instead of an object, while the REST API returned it correctly as an object.

This change brings consistency between REST and GraphQL responses for _map fields that rely on JSON string values (specifically block editor fields). It adheres to the original field contract by only enriching existing base keys, avoiding the introduction of unexpected fields in the response.

Original

"blockEditor_raw": "{\"type\":\"doc\",\"attrs\":{\"charCount\":4,\"wordCount\":1,\"readingTime\":1},\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"test\"}]}]}",
"blockEditor": "{\"type\":\"doc\",\"attrs\":{\"charCount\":4,\"wordCount\":1,\"readingTime\":1},\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"test\"}]}]}"

Updatetd

"blockEditor_raw": "{\"type\":\"doc\",\"attrs\":{\"charCount\":4,\"wordCount\":1,\"readingTime\":1},\"content\":[{\"type\":\"paragraph\",\"attrs\":{\"textAlign\":null},\"content\":[{\"type\":\"text\",\"text\":\"test\"}]}]}",
"blockEditor": {
  "type": "doc",
  "attrs": {
    "charCount": 4,
    "wordCount": 1,
    "readingTime": 1
  },
  "content": [
    {
      "type": "paragraph",
      "attrs": {
        "textAlign": null
      },
      "content": [
        {
          "type": "text",
          "text": "test"
        }
      ]
    }
  ]
}

…rlcontentmap-is-a-json-string-instead-of-an-object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQL: Block Editor field for urlContentMap is a JSON String instead of an object
2 participants