wpengine / wpengine/wp-graphql-content-blocks
Implement Block Supports as GraphQL Interfaces
@colinmurphy is already working on this.
Since May 8, 2025.
- Dominant language
- PHP
- Stars
- 149
- Forks
- 16
- PR merge metrics
- No merged PRs in 30d
Description
⚠️ 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:
- Bloated schema / queries / userland codebases*, since you can't write generic fragments
- Schema conflicts / inconsistencies, as different blocks implement the same value as different types ( e.g. an int vs a string
attributes.height) - Prone to breaking on Gutenberg updates (e.g when they notice and patch those type discrepancies)
- Suboptimal DX (e.g instead of an int or a string,
attributes.heightshould be aCssMeasurement<{$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 https://github.com/rtCamp/wp-graphql-content-blocks/pull/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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.