Description
Describe the Bug
For GraphQL requests we allready know which relations should be resolved and which fields are requested. Use this information to only fetch spartial fieldset and relations instead of the complete document.
So it should be rather easy to translate the graphql query to the required setting on select and populate for the request.
I think the note from the select API also applies for the GraphQL queries:
To perform querying with select efficiently, Payload implements your select query on the database level. Because of that, your beforeRead and afterRead hooks may not receive the full doc.
So perhaps the rollout of this feature should be done via a feature flag?
Link to the code that reproduces this issue
This is a private repo.
Reproduction Steps
We have a GraphQL request against a collection which has a lot of very deeply nested relations.
The REST API for a call against a document in that collection without select and populate APIs returns a json document which has a size of 1,5 MB.
The GraphQL API for a call against a document in that collection returns a json document which has only a size of 16KB.
However how it currently internally works is that the GraphQL API does actually do the 1,5 MB call with all the unrequired data and then only "re-formats" the data to the 16kb. There are a lof of unnecessary data loading and database requests.
Which area(s) are affected? (Select all that apply)
db-postgres
Environment Info
Payload: 3.20.0
NodeJS: 22.16
Next.js 15.1.6