Skip to content

Conversation

@jhb-dev
Copy link
Contributor

@jhb-dev jhb-dev commented Dec 8, 2025

What?

Fix GraphQL API select flag returning empty arrays for relationship and upload fields when using MongoDB.

Why?

When using the GraphQL API with select: true, relationship fields were being returned as empty arrays instead of the actual populated data. This issue only affected MongoDB, not SQLite/Postgres.
The root cause was in buildProjectionFromSelect.ts. When GraphQL builds a select object, it creates nested objects for relationship fields (e.g., { hasOne: { id: true, text: true } }) to indicate which fields should be selected from the populated relationship. However, the MongoDB projection builder only checked for select[field.name] === true at line 65, which doesn't match when the value is an object. The relationship fields then fell through to the switch statement which had no case for relationship or upload types, causing them to be silently skipped from the projection. Without the relationship field in the MongoDB projection, the document was returned without the relationship IDs, so the population phase had nothing to populate - resulting in empty arrays.

How?

Added a switch case for relationship and upload field types in buildProjectionFromSelect.ts that adds the field to the MongoDB projection. This ensures the raw relationship IDs are included in the query result, allowing the population logic to work correctly.

Also added two GraphQL integration tests that verify relationship fields (both regular and polymorphic) are properly returned when using the select flag.

Fixes #14467

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GraphQL API select flag returns relationship fields as empty arrays

1 participant