Replies: 2 comments 2 replies
|
I don't think this considers the pagination and it's wrap-type marker interface. Removal is ofc. easy, but what would be the sanction path forward. It's easy to say dataloader+AEL, but we would need specifics. Also from https://laravel.com/docs/13.x/eloquent-relationships#automatic-eager-loading
It would be irresponsible to bet on that IMHO. |
|
Of course this was a topic always on my mind since I was left being the only regular contributor and actually never truly using SelectFields (having never seen the value vs. the dataloader concept, etc.). Anyway, I'm presenting "The Removal": I got in touch with the rebing/ owner and with their help I created the counter-part too: The goal now being that the final 10.0.0 release would already not include SelectFields anymore and would be accompanied with the 1.0.0 release of rebing/graphql-laravel-select-fields. Quite some architectural things had to happen to make this possible, i.e. the invention of I tried to make it mostly drop-in compatible So for the most basic use-case "it should just work ™️". Otherwise, I tried to be detailed in the readme/upgrading guides. I believe this is still not the final change for the 10.0.0 release. I think we need to give more guidance on how a non-SelectFields world looks like in practice. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Proposal: Deprecation of the
SelectFieldsComponentContext
SelectFields(~650 lines, ~110 test files) analyzes the GraphQL AST to build optimized->select()and->with()Eloquent calls. Over time it has become a black box — tightly coupled to Eloquent internals, hard to debug, and difficult to maintain or extend safely. Bug reports and edge cases (unions, interfaces, morphs, MongoDB, nested wrapping types) tend to surface in ways that are hard to reason about without deep knowledge of the component.With Laravel's Automatic Eager Loading (Laravel 12/13), the framework now natively solves N+1 — which was the primary reason
SelectFieldsexists. This library also already "ship" (encourages use) with Dataloaders, the standard GraphQL pattern for N+1 prevention, which work with any data source via webonyx/graphql-php's deferred resolution.Comparison
SELECT col1, col2SELECT *SELECT *(customizable per loader)config['query']closures receive args + ctx$args,$contextconstrainedEagerLoad/ scopes (model level)model,alias,selectable,always, etc.Bottom line: 95% of SelectFields' value was eager loading — now covered by both AEL and Dataloaders. The only truly unique feature is automatic column selection via AST analysis, achievable manually in a loader with
->select([...]). Dataloaders also cover context-aware relation scoping, which was considered a unique SelectFields selling point.Options
rebing/graphql-laravel)Option A moves the code but doesn't solve the black-box problem — circular dependency risk, can't evolve independently.
Option B enables a clean evolution path but has the highest effort (contracts, adapter, test migration).
Option C eliminates ~650 lines + ~110 tests, simplifies the resolver API, aligns with framework direction. Breaking change, but the migration path is well-defined.
Breaking Changes & Alternatives
SelectFieldsinjection in resolversconfig['always']/config['alias']/config['selectable']$appends,$hidden, accessors; or control in the loader/resolverconfig['query'](custom query with GraphQL context)$argsand$context(see example below). AEL scopes have no GraphQL context accessSELECToptimization->select([...])inside the loader (see example below).SELECT *is fine for most appsMigration paths (Option C)
SelectFieldsusage, let Laravel handle eager loading. Suitable for most Eloquent-only apps.A migration guide with before/after examples would be essential.
The Core Questions
1. Is column-level selection worth the complexity?
It matters mainly for tables with 50+ columns, blob/text fields, or high-throughput APIs. For most apps,
SELECT *is fine.Column selection in a Dataloader
2. Do you rely on context-aware relation queries?
config['query']closures receive GraphQL arguments and context. Laravel AEL scopes have no GraphQL context access — but Dataloaders do:Context-aware loading with Dataloaders
This means context-aware relation queries do not favor keeping SelectFields.
3. Does the query execution model matter to you?
SelectFields is preventive (single upfront query), AEL is reactive (lazy trigger + batch), Dataloaders are deferred (collect keys, then bulk fetch). All three avoid N+1 effectively. The practical difference is negligible for most applications.
Recommendation
Option C (remove entirely) appears to be the strongest path forward. Laravel AEL + Dataloaders cover every SelectFields use case with clearer separation of concerns and lower maintenance burden.
Discussion
SelectFields? Which features specifically?->select()inside a dataloader)We'd love to hear the community's opinion on this topic.
Thanks!
All reactions