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
This RFC proposes a centralized registry for mapping WordPress user options to the WPGraphQL schema, enabling both core and plugins to declaratively expose user profile fields without manually writing resolvers and input handlers.
Similar to our discussion about options, I'd love at some point to have a more formal way to map registered user options to the schema more programmatically (i.e. when a plugin adds fields to the user profile, I'd love for those fields to automatically map to the schema)
Problem
Currently, exposing user options in the GraphQL schema requires:
Adding a resolver closure in Model/User.php
Registering the field definition in Type/ObjectType/User.php
Adding mutation input handling in the mutation classes
Handling type coercion manually (e.g., WordPress stores booleans as 'true'/'false' strings)
Handling defaults manually (e.g., get_user_option() returns false when not set)
Each plugin that adds user profile fields must repeat this boilerplate via register_graphql_field(). There's no standardized way to:
Define the WordPress option key to GraphQL field mapping
Specify type coercion rules
Declare defaults
Automatically generate both query fields AND mutation inputs from a single registration
Proposed Solution
register_graphql_user_option()
A new registration function that maps a WordPress user option to a GraphQL field on the User type, with automatic resolver generation, type coercion, default handling, and optional mutation support.
Summary
This RFC proposes a centralized registry for mapping WordPress user options to the WPGraphQL schema, enabling both core and plugins to declaratively expose user profile fields without manually writing resolvers and input handlers.
This was suggested by @jasonbahl in the review of #3551:
Problem
Currently, exposing user options in the GraphQL schema requires:
Model/User.phpType/ObjectType/User.php'true'/'false'strings)get_user_option()returnsfalsewhen not set)Each plugin that adds user profile fields must repeat this boilerplate via
register_graphql_field(). There's no standardized way to:Proposed Solution
register_graphql_user_option()A new registration function that maps a WordPress user option to a GraphQL field on the
Usertype, with automatic resolver generation, type coercion, default handling, and optional mutation support.Boolean Convenience
For the common pattern of WordPress string-boolean options:
Plugin Usage
Plugins that add user profile fields could register them in a single call:
Architecture
Registry Class
A new
UserOptionRegistryclass (similar toTypeRegistry) that:Model/User.phpfield resolvers at runtimeType/ObjectType/User.phpfield definitionsupdateUser/createUsersanitize_callbackduring mutationsCore Dogfooding
WPGraphQL core would use this registry for its own fields, replacing the current manual implementation:
Type Coercion Map
Boolean'true'/'false''true' === $val$val ? 'true' : 'false'Stringsanitize_text_field()Intabsint()absint()Floatfloatval()floatval()Scope
Phase 1 (MVP)
register_graphql_user_option()functionPhase 2
updateUser,createUser)sanitize_callbacksupportauth_callbackfor field-level permission controlPhase 3
graphql_user_option_value, etc.)register_graphql_post_option(), etc.)Open Questions
get_user_option()orget_user_meta()under the hood? (Leaningget_user_option()for multisite compatibility, per @jasonbahl's feedback on feat: add core user admin preferences fields to User type #3551)register_graphql_user_option()vsregister_graphql_user_meta()vsregister_graphql_user_field()?Related