Skip to content

Releases: wpengine/wp-graphql-content-blocks

v4.8.0

17 Feb 19:18
41e75bd
Compare
Choose a tag to compare

Minor Changes

  • 742f18a: # Querying Object-Type Block Attributes in WPGraphQL

    Overview

    With this update, you can now query object-type block attributes with each property individually, provided that the typed structure is defined in the class typed_object_attributes property or through a WordPress filter.

    How It Works

    The typed_object_attributes is a filterable array that defines the expected typed structure for object-type block attributes.

    • The keys in typed_object_attributes correspond to object attribute names in the block.
    • Each value is an associative array, where:
      • The key represents the property name inside the object.
      • The value defines the WPGraphQL type (e.g., string, integer, object, etc.).
    • If a block attribute has a specified typed structure, only the properties listed within it will be processed.

    Defining Typed Object Attributes

    Typed object attributes can be defined in two ways:

    1. In a Child Class (typed_object_attributes property)

    Developers can extend the Block class and specify typed properties directly:

    class CustomMovieBlock extends Block {
    	/**
    	 * {@inheritDoc}
    	 *
    	 * @var array<string, array<string, "array"|"boolean"|"number"|"integer"|"object"|"rich-text"|"string">>
    	 */
    	protected array $typed_object_attributes = [
    		'film' => [
    			'id'         => 'integer',
    			'title'      => 'string',
    			'director'   => 'string',
    			'soundtrack' => 'object',
    		],
    		'soundtrack' => [
    			'title'  => 'string',
    			'artist' => 'string'
    		],
    	];
    }

    2. Via WordPress Filter

    You can also define typed structures dynamically using a WordPress filter.

    add_filter(
        'wpgraphql_content_blocks_object_typing_my-custom-plugin_movie-block',
        function () {
            return [
                'film'       => [
                    'id'         => 'integer',
                    'title'      => 'string',
                    'director'   => 'string',
                    'soundtrack' => 'object',
                ],
                'soundtrack' => [
                    'title'  => 'string',
                    'artist' => 'string'
                ],
            ];
        }
    );

    Filter Naming Convention

    To apply custom typing via a filter, use the following format:

    wpgraphql_content_blocks_object_typing_{block-name}
    
    • Replace / in the block name with -.
    • Example:
      • Block name: my-custom-plugin/movie-block
      • Filter name: wpgraphql_content_blocks_object_typing_my-custom-plugin_movie-block

    Example:

    Example block.json Definition

    If the block has attributes defined as objects, like this:

    "attributes": {
        "film": {
          "type": "object",
          "default": {
            "id": 1,
            "title": "The Matrix",
            "director": "Director Name"
          }
        },
        "soundtrack": {
          "type": "object",
          "default": {
            "title": "The Matrix Revolutions...",
            "artist": "Artist Name"
          }
        }
    }

    This means:

    • The film attribute contains id, title, director.
    • The soundtrack attribute contains title and artist.

    WPGraphQL Query Example

    Once the typed object attributes are defined, you can query them individually in WPGraphQL.

    fragment Movie on MyCustomPluginMovieBlock {
      attributes {
        film {
          id
          title
          director
          soundtrack {
            title
          }
        }
        soundtrack {
          title
          artist
        }
      }
    }
    
    query GetAllPostsWhichSupportBlockEditor {
      posts {
        edges {
          node {
            editorBlocks {
              __typename
              name
              ...Movie
            }
          }
        }
      }
    }

v4.7.0

11 Feb 18:36
25785cd
Compare
Choose a tag to compare

Minor Changes

  • 82c6080: Adds support for resolving and returning related term items as a terms connection for the CorePostTerms block along with taxonomy connection.
    Adds support for resolving and returning the prefix and suffix items within the correspondent fields of the CorePostTerms block.

    query TestPostTerms($uri: String! = "test-terms") {
      nodeByUri(uri: $uri) {
        id
        uri
        ... on NodeWithPostEditorBlocks {
          editorBlocks {
            __typename
            ... on CorePostTerms {
              prefix
              suffix
              taxonomy {
                __typename
                node {
                  __typename
                  id
                  name
                }
              }
              terms {
                __typename
                nodes {
                  __typename
                  id
                  name
                }
              }
            }
          }
        }
      }
    }

v4.6.0

06 Feb 17:04
8bd5bd4
Compare
Choose a tag to compare

Minor Changes

v4.5.0

28 Jan 10:02
fcca872
Compare
Choose a tag to compare

Minor Changes

  • b133a1b: Added WP GraphQL as a required plugin.

  • b813352: Adds support for resolving and returning navigation items within the CoreNavigation innerBlocks for WPGraphQL Content Blocks.

    {
      posts {
        nodes {
          editorBlocks {
            ... on CoreNavigation {
              type
              name
              innerBlocks {
                type
                name
              }
              attributes {
                ref
              }
            }
          }
        }
      }
    }
    {
      "data": {
        "posts": {
          "nodes": [
            {
              "editorBlocks": [
                {
                  "type": "CoreNavigation",
                  "name": "core/navigation",
                  "innerBlocks": [
                    {
                      "type": "CorePageList",
                      "name": "core/page-list"
                    },
                    {
                      "type": "CoreNavigationLink",
                      "name": "core/navigation-link"
                    }
                  ],
                  "attributes": {
                    "ref": 31
                  }
                }
              ]
            },
            {
              "editorBlocks": [{}]
            }
          ]
        }
      }
    }

Patch Changes

  • dec27c3: feat: Added a CoreGroup block class to fix an issue with a missing attribute cssClassName

v4.4.0

14 Jan 10:45
8bb911a
Compare
Choose a tag to compare

Minor Changes

  • 756471a: feat: add support for resolving PostContent blocks
  • 19f6e27: feat: add support for resolving Template Part blocks
  • 4c548c3: feat: add support for resolving Block Patterns

v4.3.2

12 Dec 16:51
cab682e
Compare
Choose a tag to compare

Patch Changes

  • c8832fc: fix: improve handling of empty blocks in ContentBlocksResolver.
  • 9a2ebf7: fix: Ensure correct EditorBlock.type field resolution.

v4.3.1

14 Nov 17:21
c09aeb7
Compare
Choose a tag to compare

Patch Changes

  • f99f768: Correct version definition

v4.3.0

11 Nov 16:32
6f5c0b6
Compare
Choose a tag to compare

Minor Changes

  • d123b81: dev: Refactor attribute resolution into Data\BlockAttributeResolver
  • d123b81: feat: add support for parsing (deprecated) meta attributes.

Patch Changes

  • 96bad40: tests: fix setUp()/tearDown() methods to prevent PHPUnit lifecycle issues.
  • f898d61: tests : Add tests for CoreList and CoreListItem blocks.
  • 3b32f06: tests : Backfill tests for Core Image block.
  • 7301ed9: tests: Add tests for CoreHeading block
  • d4d7374: tests : Backfill tests for Core Video block.
  • 3a1157b: fix: Correctly parse nested attribute and tag sources.
  • 8b2e168: tests : Add tests for CoreSeparator block.
  • 962081d: tests: Add tests for CoreParagraph block
  • 5915c06: tests: Add tests for CorePreformatted Block
  • 3a1157b: tests: backfill tests for CoreTable attributes.
  • a02e75a: tests: Add tests for CoreCode Block
  • c6bdab0: tests : Add tests for CoreQuote block.
  • a38e479: tests : backfill tests for ContentBlockResolver

v4.2.0

19 Sep 17:24
3fb784d
Compare
Choose a tag to compare

Minor Changes

  • 766737d: fix: cleanup constants and refactor autoload handling to improve Composer compatibility.
  • 7514021: chore: Update Composer dev-dependencies to their latest (semver-compatible) versions.
  • b64583f: dev: Add wpgraphql_content_blocks_pre_resolve_blocks and wp_graphql_content_blocks_resolve_blocks filters.
  • 179948c: dev: make PluginUpdater namespaced functions PSR-4 compatible.
  • bced76d: feat: expose EditorBlock.type field

Patch Changes

  • de885f1: Skip the Sonar Qube workflow if the user that opened the PR is not a member of the Github org
  • 6ced628: Fix: prevent fatal errors when get_current_screen() is unset.
  • 58b6792: chore: remediate non-code PHPStan errors in phpstan-baseline.neon
  • c3e11b1: ci: test against WordPress 6.6
  • 27f459f: tests: fix PHP deprecation notices
  • 4f4b851: tests: fix order of expected/actual values passed to asserts.
  • 89b6c60: tests: lint and format PHPUnit tests
  • 65f0c2d: Update @since @todo tags and @todo placeholders in _deprecated_function calls

v4.1.0

14 Aug 10:21
6192a96
Compare
Choose a tag to compare

Minor Changes

  • 6241c4e: fix: prevent fatal errors by improving type-safety and returning early when parsing HTML.
    The following methods have been deprecated for their stricter-typed counterparts:
    • DOMHelpers::parseAttribute() => ::parse_attribute()
    • DOMHelpers::parseFirstNodeAttribute() => ::parse_first_node_attribute()
    • DOMHelpers::parseHTML() => ::parse_html()
    • DOMHelpers::getElementsFromHTML() => ::get_elements_from_html()
    • DOMHelpers::parseText() => ::parse_text()
    • DOMHelpers::findNodes()=> ::find_nodes()

Patch Changes

  • 2b947dc: chore: update Composer dev-dependencies and fix resulting issues.
  • 205da8c: ci: replace docker-compose commands with docker compose
  • 5c21ce3: Bug fix. Reusable block isn't resolved inside innerBlocks.