You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With WPGraphQL v2.0 now released and graphql-php oneOf support nearly ready (PR #1715), we can now move forward with implementing oneOf directive (a.k.a OneOf Input Type) support.
We've completed an audit of the current schema and developed an implementation plan.
Summary
The oneOf directive represents a significant opportunity to improve WPGraphQL's developer experience and schema maintainability. Our audit identified 26+ specific opportunities across 4 main categories, with potential to eliminate hundreds of lines of complex input types while making the API more intuitive and type-safe.
Business Case
Developer Experience Benefits
50% reduction in schema complexity for common queries
Elimination of confusing id/idType patterns that can frustrate and confuse developers
Type-safe validation allows more complex input patters while preventing invalid input combinations
Intuitive API that matches modern GraphQL expectations
Maintainer Benefits
Reduced support burden - ideally fewer "how do I query X?" questions
Schema maintainability - less enum proliferation and cleaner patterns
WordPress alignment - better handling of WordPress's complex tax query and meta query system
Future-proofing - enables advanced features like block editor mutations and ACF mutations
Technical Improvements
Better error messages with specific validation feedback
Extensible patterns for plugin developers
Performance optimizations through clearer query intentions, and ultimately smaller schema footprint
Modern GraphQL practices keeping WPGraphQL cutting-edge and allowing previously-blocked use cases
Current State Analysis
Identified oneOf Opportunities
1. Singular Field Arguments (6+ immediate opportunities)
Currently using the id + idType pattern:
# CURRENT (can be confusing)post(id: "hello-world", idType: SLUG) { title }
user(id: "john@example.com", idType: EMAIL) { name }
# PROPOSED (more intuitive) post(by: { slug: "hello-world" }) { title }
user(by: { email: "john@example.com" }) { name }
Affected fields:post, page, ( and custom post types), mediaItem, user, category, tag, (and custom taxonomies)
typeRootQuery {
# Keep for backward compatibilitypost(id: ID!@deprecated(reason: "Use by argument instead"), idType: PostIdType@deprecated(reason: "Use by argument instead")): Post # New oneOf approachpost(by: PostIdentifierInput!): Post
}
Validation: Throw error if both old and new patterns used simultaneously
Phase 2 (or 3?) : Connection Filtering & Sorting
Priority: HIGH | Complexity: MEDIUM | Impact: HIGH
Replace complex where arguments with structured filter and sort:
Support burden reduction (might be hard to measure, and could actually be an initial support burden increase as change always tends to do that a bit)
Adoption rate of new patterns vs deprecated ones (might be hard to measure externally)
Extension ecosystem compatibility and adoption
📋 Original RFC (February 2024)
Click to expand original proposal
The @OneOf directive allows for polymorphism for input types, similar to how Interfaces and Unions work for Queries. This is a feature that I've been wanting to support for years.
Having formal support for oneOf input types will unlock a LOT of currently "blocked" features and allow us to improve a lot of areas of the Schema over time.
I propose that we contribute to the effort of adding @OneOf support to GraphQL-PHP.
Then, update WPGraphQL to use the version of graphql-php that supports the oneOf directive.
Then, start implementing features using the oneOf directive.
Some loose ideas on where we could benefit from oneOf inputs:
Singular Node fetching:
For example, instead of post( id: $id idType: $idType ) the oneOf directive could be used to allow the following:
The oneOf directive will likely have impact on the initiative to improve connection filtering and sorting: #1385
Polymorphic Mutations:
Not making use of oneOf directive and using workarounds like the combination of fields ( i.e. post(id: $id idType: $idType)).
Right now, mutations on polymorphic list types such as Gutenberg Blocks and ACF Flex Fields are essentially impossible or at least VERY clunky without oneOf support.
With oneOf support, we could handle things like updating a list of blocks like so:
If we update to latest GraphQL-PHP in order to take advantage of newer features like this, we would likely need to formally drop support of older versions of PHP as GraphQL-PHP supports php formally supports PHP 7.4+ and WPGraphQL currently supports PHP 7.1+.
Refactoring parts of the Schema to make use of the oneOf directive MIGHT ultimately lead to breaking changes. I think a lot of things could be done in a backward compatible way though.
There might be some under the hood breaking changes as part of the upgrade that we would need to track and note for any release that included the upgrade.
If we were to support the oneOf input type, GraphiQL IDE would need to know how to interact with it. Specifically the "Query Composer" feature that provides UI elements for users to input values. It would need to know how to properly show users a UI that conveys: Chose "one of" these possible inputs.
🔄 UPDATE - July 7, 2025
With WPGraphQL v2.0 now released and graphql-php oneOf support nearly ready (PR #1715), we can now move forward with implementing oneOf directive (a.k.a OneOf Input Type) support.
We've completed an audit of the current schema and developed an implementation plan.
Summary
The oneOf directive represents a significant opportunity to improve WPGraphQL's developer experience and schema maintainability. Our audit identified 26+ specific opportunities across 4 main categories, with potential to eliminate hundreds of lines of complex input types while making the API more intuitive and type-safe.
Business Case
Developer Experience Benefits
id/idTypepatterns that can frustrate and confuse developersMaintainer Benefits
Technical Improvements
Current State Analysis
Identified oneOf Opportunities
1. Singular Field Arguments (6+ immediate opportunities)
Currently using the
id + idTypepattern:Affected fields:
post,page, ( and custom post types),mediaItem,user,category,tag, (and custom taxonomies)2. Connection Filtering (20+ input types affected)
Current
wherearguments allow contradictory combinations:3. Mutation Inputs (15+ mutations affected)
Enable polymorphic content creation and relationship management:
4. Advanced Features (future opportunities)
Implementation Strategy
Phase 1: Singular Field Arguments
Priority: HIGH | Complexity: LOW | Impact: HIGH
Create identifier input types:
Add new
byargument alongside existing pattern:Validation: Throw error if both old and new patterns used simultaneously
Phase 2 (or 3?) : Connection Filtering & Sorting
Priority: HIGH | Complexity: MEDIUM | Impact: HIGH
Replace complex
wherearguments with structuredfilterandsort:Benefits:
Phase 3 (or 2?): Mutation Inputs
Priority: MEDIUM | Complexity: MEDIUM | Impact: MEDIUM
Phase 4: Advanced Features (8-12 weeks)
Priority: MEDIUM | Complexity: HIGH | Impact: HIGH
Enable block editor mutations and advanced use cases:
Migration Strategy
Backward Compatibility
posts( where: $where )orposts( sort: $sort, filter: $filter )should both work for some time)posts( where: $where filter: $filter sort: $sort )Developer Support
Considerations
@oneOfdirective spec graphql/graphiql#3768)@oneOfinput types dotansimha/graphql-code-generator#7886))Next Steps
@oneOfInput Object Directive webonyx/graphql-php#1715 is merged and released)Success Metrics
📋 Original RFC (February 2024)
Click to expand original proposal
The @OneOf directive allows for polymorphism for input types, similar to how Interfaces and Unions work for Queries. This is a feature that I've been wanting to support for years.
The GraphQL Spec has an RFC here: graphql/graphql-spec#825
GraphQL.js recently merged the implementation: graphql/graphql-js#3513
And GraphQL-PHP is accepting PRs that introduce the feature: webonyx/graphql-php#619 (comment)
Having formal support for oneOf input types will unlock a LOT of currently "blocked" features and allow us to improve a lot of areas of the Schema over time.
I propose that we contribute to the effort of adding @OneOf support to GraphQL-PHP.
Then, update WPGraphQL to use the version of graphql-php that supports the oneOf directive.
Then, start implementing features using the oneOf directive.
Some loose ideas on where we could benefit from oneOf inputs:
Singular Node fetching:
For example, instead of
post( id: $id idType: $idType )the oneOf directive could be used to allow the following:Connection filtering/sorting:
The oneOf directive will likely have impact on the initiative to improve connection filtering and sorting: #1385
Polymorphic Mutations:
Not making use of oneOf directive and using workarounds like the combination of fields ( i.e.
post(id: $id idType: $idType)).Right now, mutations on polymorphic list types such as Gutenberg Blocks and ACF Flex Fields are essentially impossible or at least VERY clunky without oneOf support.
With oneOf support, we could handle things like updating a list of blocks like so:
We could also have polymorphic creation mutations, such as:
This would simplify the Schema quite a bit and likely DRY up some underlying execution logic as well.
For example:
Additional Context
If we update to latest GraphQL-PHP in order to take advantage of newer features like this, we would likely need to formally drop support of older versions of PHP as GraphQL-PHP supports php formally supports PHP 7.4+ and WPGraphQL currently supports PHP 7.1+.
Refactoring parts of the Schema to make use of the oneOf directive MIGHT ultimately lead to breaking changes. I think a lot of things could be done in a backward compatible way though.
There might be some under the hood breaking changes as part of the upgrade that we would need to track and note for any release that included the upgrade.
If we were to support the oneOf input type, GraphiQL IDE would need to know how to interact with it. Specifically the "Query Composer" feature that provides UI elements for users to input values. It would need to know how to properly show users a UI that conveys: Chose "one of" these possible inputs.