The implementation of resolveType and isTypeOf very flexible for a reason: it is extremely application specific. It depends on the database, data models, similar types, etc. Some servers may have separate ES6 classes for all their models, especially if you use ORM, where it creates instances of these classes when querying the database. But ORM is not required. And you do not need to instantiate other classes to determine the type of GraphQL.
In some cases, you can determine the type solely from the properties of objects. If this does not apply to your application, there are things you can do to give clues. Here is an example of SQL.
SELECT id, body, author_id, post_id, 'Comment' AS "$type"
This query provides a "type hint", an optional computed column, so the resolveType implementation is a simple property search. Other DBMSs may use a similar strategy.
source share