feat: configurable field-accessor prefixes (SchemaFactory::stripFieldPrefixes) - #827
Merged
oojacoboo merged 2 commits intoAug 20, 2026
Merged
Conversation
…Prefixes) Generalizes the hasser support proposed in thecodingmachine#766 into a configurable set of accessor prefixes. SchemaFactory::stripFieldPrefixes(getters:, setters:) sets the method-name prefixes stripped to derive field names and matched when resolving property accessors such as #[SourceField]. Adding "has" to the getters exposes hassers like hasStock(). Prefixes are stripped only on a camelCase boundary (the character after the prefix must be uppercase), so genuine accessors like isEnabled() become enabled while ordinary words such as issue() or hashKey() are left untouched. Defaults (getters get/is, setters set) preserve the historical behavior, so the change is backward compatible.
oojacoboo
force-pushed
the
feat/strip-field-prefixes
branch
from
August 19, 2026 20:34
0847d0b to
1e2978b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #827 +/- ##
============================================
- Coverage 95.72% 91.79% -3.94%
- Complexity 1773 2101 +328
============================================
Files 154 203 +49
Lines 4586 5630 +1044
============================================
+ Hits 4390 5168 +778
- Misses 196 462 +266 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
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
Adds
SchemaFactory::stripFieldPrefixes(getters:, setters:)to configure the method-name prefixes GraphQLite strips to derive field names and matches when resolving property accessors:This generalizes the hasser support proposed in #766 (thanks @adynemo). Adding
hasto the getters exposes hassers such ashasStock()via#[SourceField],#[Field], etc. The defaults (getters: ['get', 'is'],setters: ['set']) preserve the historical behavior, so the feature is opt-in.Exact-case boundary rule
Prefixes are now stripped only when they sit on a real camelCase boundary (the character right after the prefix is uppercase). So
isEnabled()becomesenabledandhasHKey()becomeshKey, but ordinary words such asissue(),hashKey(),gettext(),settings()andsetup()are left untouched.This replaces the previous length-only check (
str_starts_with($m, 'is') && strlen($m) > 2), which mis-stripped any word starting with a prefix (issue()gave a field namedsue,settings()gavetings). See the discussion in #766.Breaking change
The exact-case rule changes field-name derivation for method names where a prefix is followed by a lowercase letter. The change is always in the "less stripping" direction and only affects names that were almost certainly being mis-stripped:
getName()namename(unchanged)isEnabled()enabledenabled(unchanged)issue()sueissuegettext()textgettextsettings()tingssettingsMigration: if a
#[Field]/#[SourceField]method relied on the old behavior, set an explicit name with#[Field(name:)]or the source field'sname. Documented in CHANGELOG under 8.4.0.Design notes
FieldAccessorPrefixesvalue object owns the two prefix lists and the boundary rule, soNamingStrategy(naming) andPropertyAccessor(lookup) share one source of truth.NamingStrategyInterfaceis unchanged; prefixes are a construction-time detail of the defaultNamingStrategy.PropertyAccessor::findGetter/findSetter, theFieldsBuilderandNamingStrategyconstructors), so existing callers are unaffected.PropertyAccessor::getValue/setValueintentionally keep the default prefixes: they back property#[Field]reads/writes against an existing property, whereas the hasser/#[SourceField]path resolves the method at build time and invokes it throughSourceMethodResolver.Tests
FieldAccessorPrefixesTest(strip logic,hasSetterPrefix, edge cases), plus additions toNamingStrategyTestandPropertyAccessorTest.StripFieldPrefixesTest): a#[SourceField]hasser (getter side) and a custom-prefixed setter input field (setter side) each resolve and hydrate only when the prefix is configured.