graphql - graphql 对所有或少数模式字段的单选查询
问题描述
我有一个像下面这样的graphql模式
const SellerjobtypeType = new GraphQLObjectType({
name: 'Sellerjobtype',
fields: () => ({
id: { type: GraphQLString },
sellerName: { type: GraphQLString },
sellerAdd: { type: GraphQLString },
status: { type: GraphQLString },
requestRaiseTime: { type: GraphQLString },
percent: { type: GraphQLString },
runtime: { type: GraphQLString },
jobid: { type: new GraphQLNonNull(GraphQLString) },
specialinstructions: { type: GraphQLString }
})
});
当我编写 graphql 服务器代码以获取 SellerName 的所有 SellerjobtypeType 时,我必须创建一个解析器端点。
sellerjobtype: {
type: SellerjobtypeType,
args: { id: { type: GraphQLString}},
resolve(parent, args) {
return Sellerjobtype.findById(args.id);
}
}
这将仅基于 id 进行搜索
现在我想按卖家名称搜索我创建了另一个端点
sellerjobtype2: {
type: SellerjobtypeType,
args: { sellerName: { type: GraphQLString}},
resolve(parent, args) {
return myObj.findByName(args.sellerName);
}
}
如果我必须搜索其他字段,我会创建另一个端点。
这是否违背了不必创建多个端点的 graphql 目的。我想我犯了一个错误。请建议我如何创建自定义端点,该端点可以根据 SellerjobtypeType 中的全部或少数字段处理所有搜索
解决方案
推荐阅读
- ios - UICollectionView 比 NavigationController 大
- javascript - 如何避免添加重复的数组条目,而是更新已经存在的条目
- c++ - 纯虚函数的继承
- c++ - C ++中的访问冲突异常
- node.js - 400 BadRequest:缺少凭据 feathersjs authentication-local
- javascript - 切片并推送到带有字符串和数字的二维数组
- explode - 查询多行文本区域的每一行
- r - R组合函数
- openshift - openshift 入门项目 - 无法提取构建器映像
- android - 带有 JUnit 测试的 Dagger