Given the following database schema:
Table items
- title (string/varchar)
- ownerId (int/ForeignKey) // foreign key to
users.userId
Table users
- userId (int/PrimaryKey)
- username (string/varchar)
Now, if I wanted to query all items including the owner's username, so my GraphQL query would look like this:
items {
title
ownerId
username
}
How would that look like on the backend? Would I have to introduce a new entity like
record class ItemWithUsername(
string Title,
string OwnerId,
string Username
)
and write an resolver for it or is there a more generic solution (e.g. not having to write a new type) to this? I know a user of my GraphQL API could first query all items (only ownerId, username) and then query for the relevant username from users (via ownerId), but that would require many network round trips, which is what I want to prevent.