不确定我是否正确理解了您的问题。您能否更详细地说明您要做什么?
你是不是在尝试任意深度嵌套的自我关系?然后你可以做这样的事情:
type Category {
id: ID! @id
name: String!
subCategory: Category @relation(name:"SubToParent"link: INLINE)
parentCategory: Category @relation(name: "SubToParent")
}
创建三个级别将使用此查询:
mutation createCategory {
createCategory(
data: {
name: "firstLevel"
subCategory: {
create: {
name: "secondLevel"
subCategory: { create: { name: "thirdLevel" } }
}
}
}
) {
name
}
}
查询类别会给你这个响应:
query allCategories {
categories {
name
subCategory {
name
}
parentCategory {
name
}
}
}
{
"data": {
"categories": [
{
"name": "firstLevel",
"subCategory": {
"name": "secondLevel"
},
"parentCategory": null
},
{
"name": "secondLevel",
"subCategory": {
"name": "thirdLevel"
},
"parentCategory": {
"name": "firstLevel"
}
},
{
"name": "thirdLevel",
"subCategory": null,
"parentCategory": {
"name": "secondLevel"
}
}
]
}
}
我希望这会有所帮助,如果不仅仅是更详细地解释您的问题。