Support optimized select for top-level query
- [x] Added or updated tests
- [ ] Documented user facing changes
- [ ] Updated CHANGELOG.md
I made some updates from https://github.com/nuwave/lighthouse/pull/1626.
Tests passed directives
@all@find@paginate
The query builder and scout builder are not optimized.
type Query {
postsSearch(search: String @search): [Post!]! @paginate // scout builder
}
Tests passed relation types
- hasOne
- hasMany
- morphOne
- morphMany
- belongsTo
- belongsToMany
Only the root query will be optimized. The nested queries are not optimized.
type User {
name: String!
posts: [Post!]! @hasMany
}
type Post {
id: ID!
title: String!
}
type Query {
users: [User!]! @all
}
{
users {
name
posts {
id
title
}
}
}
# query logs
# optimized
select `id`, `name` from `users`
# the nested query is not optimized
select * from `posts` where `posts`.`user_id` in (1, 2) and `posts`.`deleted_at` is null
Changes Only query the selection fields.
Breaking changes
- Custom attribute needs to use
@select
public function getCompanyNameAttribute(): string
{
return $this->company->name;
}
type User {
id: ID!
companyName: String! @select(columns: ["company_id"])
}
- The result may change when using optimized select. For predictable results, you should use
@orderByhttps://dba.stackexchange.com/a/6053
Note This PR was only tested in our own project, and there may be some edge cases that are not considered.
@spawnia
Is there anything that needs to change for this pull request to be merged?
Thank you for your continued efforts on this. Unfortunately this pull request needs significant rework for the reasons I outlined in my review.
You can add the following entry to CHANGELOG.md:
### Added
- Allow optimizing `SELECT` https://github.com/nuwave/lighthouse/pull/2235 by @Lyrisbee, @bepsvpt
Thanks @spawnia, could we add a @storipress tag as well — we'll get back to this one sometime next month as we're working on some other features right now. We expect this to be done EO March
Thanks @spawnia, could we add a @storipress tag as well — we'll get back to this one sometime next month as we're working on some other features right now. We expect this to be done EO March
Sure, that sounds fine to me.