Virtual Attributes
Resolve a model getter
Getters of a model resolve the same way as columns:
ts
class PostModel extends Model {
static tableName = "post"
declare id?: number
get url() {
return `/posts/${this.id}`
}
}
const graph = r.graph({
Post: r.model(PostModel),
})gql
type Post {
id: Int!
text: String!
url: String!
}To list a getter in fields, set it to true, as a column.
Select the columns that a getter needs
The graph selects the columns of the fields that the client asks for, so a query for text and url may leave id unselected and the getter without its value. Select the columns that the getter reads when its field is resolved:
ts
const graph = r.graph({
Post: r.model(PostModel, {
fields: {
id: true,
text: true,
url: query => query.select("id"),
},
}),
})