-
Notifications
You must be signed in to change notification settings - Fork 466
feat(experiment): EmailAddress Scalar and Fields #3437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jasonbahl
wants to merge
24
commits into
wp-graphql:develop
Choose a base branch
from
jasonbahl:experiment/scalar-email-address
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(experiment): EmailAddress Scalar and Fields #3437
jasonbahl
wants to merge
24
commits into
wp-graphql:develop
from
jasonbahl:experiment/scalar-email-address
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ema, but no fields are yet configured to use it.
…mail # Conflicts: # src/Registry/TypeRegistry.php
- Add new EmailAddress scalar type with WordPress email validation - Add User.emailAddress field using EmailAddress scalar - Add Commenter.emailAddress field using EmailAddress scalar - Deprecate User.email and Commenter.email fields with proper warnings - Update User and CommentAuthor models to support emailAddress field - Add comprehensive tests for email field functionality - Maintain backward compatibility with existing email fields - Follow RFC approach for introducing new scalar fields The EmailAddress scalar validates emails using WordPress's is_email() function and sanitizes them with sanitize_email(). Deprecated fields show proper deprecation warnings and will be removed in v3.0. Resolves: wp-graphql#3313
- Add EmailAddress scalar type with built-in validation and sanitization - Move deprecated email field from Comment.php edgeFields to Deprecated.php - Add CommentToCommenterConnectionEdge.email field to Deprecated.php - Update Commenter.email and CommentAuthor.email deprecation messages - Replace hardcoded version numbers with @Next-Version placeholders - Add EmailAddress scalar registration to WPGraphQL.php - Update CommentAuthor model to include emailAddress field - Update AppContext to include EmailAddress scalar in schema This provides better type safety and validation for email addresses while maintaining backward compatibility through deprecated fields.
…nal details - fix missing adminEmail field on GeneralSettings
- Update existing docs
# Conflicts: # composer.lock
# Conflicts: # src/AppContext.php # src/Experimental/ExperimentRegistry.php
- update experiment proposal template
- update experiment proposal template
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What new experiment does this implement? Explain your changes.
This pull request implements two related experiments that introduce email address validation and type safety to WPGraphQL:
1. Email Address Scalar Experiment (
email-address-scalar)Registers a custom
EmailAddressscalar type that validates email addresses using WordPress's built-inis_email()andsanitize_email()functions. This provides automatic validation and sanitization for email fields throughout the GraphQL schema.2. Email Address Scalar Fields Experiment (
email-address-scalar-fields)Adds
emailAddressfields using theEmailAddressscalar to core WPGraphQL types including User, Commenter, CommentAuthor, and GeneralSettings. Also updates mutation inputs to accept EmailAddress values with backward compatibility for existingemailString fields.Key Features
is_email()functionemailString fields remain functional with deprecation warningsNew Functionality
EmailAddressscalar type available for use in custom field registrationsemailAddressfields on User, Commenter, CommentAuthor typesadminEmailfield on GeneralSettingsemailAddressinput fields on user mutation inputs (CreateUserInput, UpdateUserInput, RegisterUserInput)emailString fieldsRelated Experiment Proposal
Note: This PR implements experiments that were refactored from a direct core implementation. The original work was done as a feature PR but has been reorganized into the experiments system. If there is an approved experiment proposal issue, please link it here.
Experiment Details
Experiment 1: Email Address Scalar
email-address-scalaris_email()function. This provides better type safety and validation for email fields.Experiment 2: Email Address Scalar Fields
email-address-scalar-fieldsImplementation Summary
Experiment Classes
EmailAddressScalarExperimentclass extendingAbstractExperimentEmailAddressScalarFieldsExperimentclass extendingAbstractExperimentget_config(),init(), etc.)ExperimentRegistry::register_experiments()Core Changes
EmailAddressemailAddressfields on User, Commenter, CommentAuthor types (when experiment is enabled)adminEmailfield on GeneralSettings (when experiment is enabled)emailAddressinput fields on user mutation inputsemailString fieldsEmailAddressScalarFieldsExperiment::resolve_email_input()for mutation resolversSchema Changes (when enabled)
Testing Strategy
Test Coverage
tests/wpunit/Type/Scalar/EmailAddressTest.php)tests/wpunit/experiments/email-address-scalar/EmailAddressTest.php)tests/wpunit/experiments/email-address-scalar-fields/UserEmailAddressFieldsTest.php)Test Examples
Experiment Lifecycle
Activation/Deactivation
GRAPHQL_EXPERIMENTAL_FEATURESconstantgraphql_experimental_features_overridefilterBreaking Changes
Since experiments can have breaking changes, document any:
emailString fields continue to work with deprecation warnings.emailfields, but should migrate toemailAddressfields. Both fields work simultaneously, but providing both in mutations causes an error.Future Breaking Changes (if graduated):
If these experiments graduate to core, the deprecated
emailString fields would be removed in WPGraphQL v3.0. Users would need to migrate toemailAddressfields.Documentation Updates
Documentation Changes
src/Experimental/Experiment/EmailAddressScalarExperiment/README.md)src/Experimental/Experiment/EmailAddressScalarFieldsExperiment/README.md)src/Experimental/README.md)docs/custom-scalars.md)docs/default-types-and-fields.md)Future Considerations
Additional Context
Implementation Details
File Structure:
src/Experimental/Experiment/EmailAddressScalarExperiment/EmailAddressScalarExperiment.php- Main experiment classsrc/Experimental/Experiment/EmailAddressScalarExperiment/EmailAddress.php- Scalar type implementationsrc/Experimental/Experiment/EmailAddressScalarExperiment/README.md- Comprehensive documentationsrc/Experimental/Experiment/EmailAddressScalarFieldsExperiment/EmailAddressScalarFieldsExperiment.php- Main experiment classsrc/Experimental/Experiment/EmailAddressScalarFieldsExperiment/README.md- Comprehensive documentationKey Implementation Highlights:
is_email()for validation andsanitize_email()for sanitizationemailString fields continue to work with deprecation warningsemailandemailAddress, with automatic normalizationemailandemailAddressare providedGRAPHQL_DEBUGis enabled)Performance Impact
is_email()is very fastSecurity Considerations
sanitize_email()manage_optionscapability)Dependencies
EmailAddressScalarFieldsExperiment requires:
email-address-scalarexperiment to be activeThis dependency is properly enforced in the experiment registry, preventing activation without the required dependency.
Community Feedback
This implementation was refactored from a direct core feature PR (#3394) to use the experiments system, allowing for:
Feedback Channels:
Testing Notes
Some test files note that experiment loading in test environments can have timing issues. The experiments work perfectly when manually enabled via WordPress admin or wp-config.php, but programmatic enabling in tests may require additional test infrastructure improvements.