Skip to content

Implement Block Supports as GraphQL InterfacesΒ #354

@justlevine

Description

@justlevine

⚠️ Disclaimer

This is a [stub] follow-up to #136 , as @moonmeister encouraged me to start backfilling some of my bigger wish-list items instead of keeping them all for myself πŸ˜‡

Problem

Currently, Block fields and attributes are registered directly on each block type. This causes several issues:

  1. Bloated schema / queries / userland codebases*, since you can't write generic fragments
  2. Schema conflicts / inconsistencies, as different blocks implement the same value as different types ( e.g. an int vs a string attributes.height)
  3. Prone to breaking on Gutenberg updates (e.g when they notice and patch those type discrepancies)
  4. Suboptimal DX (e.g instead of an int or a string, attributes.height should be a CssMeasurement<{$size}{$unit}> )

Solution

*BlockAttribute Object types should implement GraphQL Interfaces per their Block Supports, and use that as the stable source of truth for those parts of the schema going forward.

Then and only where there is a conflict between the interfaces and what's inferred from the block.json we can coerce it on the block resolver level. The same approach can also:

  • provide stability and future-proofing (by coercing any values resolved via the interface),
  • allow for multiversion-backcompat (it's just another conditional in the resolver)
  • (eventually) provide a path for improved subjective DX, without it becoming additional tech-debt (due to the previous two points).

For example (I suck at naming things, so giving a few different styles. These are illustrative only):

  • BlockAttributesSupportsTypographyFontSize
  • BlockSupportsColorHeading
  • FilterDuotoneBlockSupportAttributes

You can see some exploratory work to this effect in rtCamp#31

Additional Notes

  • Nothing here requires a breaking change to implement, and it can be implemented incrementally.
  • An obvious future extension of this are interfaces for shared functionality on a Block level. E.g. image/media item connections, related terms, etc

Sub-issues

Metadata

Metadata

Assignees

Labels

effort: highMore than a weekimpact: highUnblocks new use cases, substantial improvement to existing feature, fixes a major bugneeds: discussionRequires a discussion to proceedscope: performanceEnhancing speed and efficiencytype: enhancementImprovements to existing functionality

Projects

Status

πŸ†• Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions