Overview
You can use hasMany
and belongsTo
field to create relations between models.
For example, our demo server has the following relations defined:
.mockend.json
{
"Post": {
"comments": {
"hasMany": "Comment"
}
},
"Comment": {
"post": {
"belongsTo": "Post"
}
}
}
REST API
Considering our previous example, a postId
foreign key will be automatically created.
You can then use postId_eq=:id
to query nested resources. For example, to get all comments for a post:
https://mockend.com/mockend/demo/comments?postId_eq=1 (opens in a new tab)
GraphQL API
In GraphQL, post
and comments
fields will be created to query parent/children resources.
For example:
{
post(id: 1) {
title
comments {
body
}
}
}
Run example query (opens in a new tab)
Last updated on January 16, 2023