【发布时间】:2019-08-01 03:58:19
【问题描述】:
我用过express-graphql,我曾经在那里做过类似的事情。
const SubCategoryType = new ObjectType({
name: 'SubCategory',
fields: () => ({
id: { type: IDType },
name: { type: StringType },
category: {
type: CategoryType,
resolve: parentValue => getCategoryBySubCategory(parentValue.id)
},
products: {
type: List(ProductType),
resolve: parentValue => getProductsBySubCategory(parentValue.id)
}
})
});
这里我有多个解析器,id and name 直接从结果中获取。并且类别和产品都有自己的数据库操作。等等。
现在我正在研究apollo-server,但我找不到复制它的方法。
例如我有一个类型
type Test {
something: String
yo: String
comment: Comment
}
type Comment {
text: String
createdAt: String
author: User
}
在我的解析器中,我想将其拆分,例如这样的
text: {
something: 'value',
yo: 'value',
comment: getComments();
}
注意:这只是我需要的表示。
【问题讨论】:
标签: graphql apollo-server