8
鑑於以下apollo服務器graphql架構 我想將它們拆分爲單獨的模塊,因此我不希望根查詢架構下的作者查詢..並希望它分離。所以我將它添加到根查詢如何在apollo graphql服務器中創建嵌套解析器
type Author {
id: Int,
firstName: String,
lastName: String
}
type authorQueries {
author(firstName: String, lastName: String): Author
}
type Query {
authorQueries: authorQueries
}
schema {
query: Query
}
之前增加了一個叫做authorQueries另一層我嘗試以下..你可以看到authorQueries添加另一層指定筆者功能之前。
Query: {
authorQueries :{
author (root, args) {
return {}
}
}
}
當Graphiql查詢,我還添加了額外的一層..
{
authorQueries {
author(firstName: "Stephen") {
id
}
}
}
我碰到下面的錯誤。
"message": "Resolve function for \"Query.authorQueries\" returned undefined",
難道沒有更好的方法,比如爲作者類型定義一個解析器,它使用了一些overgiven根參數的值? 當我不喜歡這樣,我有做了一個每次被auther在其他類型的 – user7776232
沒錯使用的解析器,你需要定義一個解析器爲每個返回一個作者,至少在目前的GraphQL實現現場。未來可能會更好。 – stubailo