Recently, I needed virtual attribute which combines or mutates original attributes.
Case 1. fullName
which combines lastName
and firstName
Case 2. studentCount
which aggregates count from relation students
I want to achieve it on GraphQL. Is there a proper way to achieve it?
Welcome @darron1217
,
Virtual fields are currently not possible by default, but there has been some discussion going on how to implement it. Checkout this RFC.
For now you could create a custom query in your GraphQL shema(s) to implement some custom logic. These docs could help you out:
Also the afterFind
Lifecycle hook could help you out realizing the ‘calculated’ logic on student fetches.
Hope this helps 