asp.net - 使用带有模式优先方法的 hotchocolate 过滤器
问题描述
我正在使用模式拦截器来配置我的模式。这是一个多租户的应用程序,所以我根据租户的配置来构建架构。我将该配置映射到 SDL 语言(模式优先方法),然后将其添加到模式构建器 ( schemaBuilder.AddDocumentFromString(...)
)。
如文档(此处)所述,“Schema-first 目前不支持过滤!”。但这是我现在可以使用的唯一方法,所以我试图找到一种解决方法。
我试过的:
手动创建输入过滤器类型并将过滤器添加到服务器(类似这样):
...
schemaBuilder.AddDocumentFromString(@"
type Query {
persons(where: PersonFilterInput): [Person]
}
input PersonFilterInput {
and: [PersonFilterInput!]
or: [PersonFilterInput!]
name: StringOperationFilterInput
}
input StringOperationFilterInput {
and: [StringOperationFilterInput!]
or: [StringOperationFilterInput!]
eq: String
neq: String
contains: String
ncontains: String
in: [String]
nin: [String]
startsWith: String
nstartsWith: String
endsWith: String
nendsWith: String
}
}
type Person {
name: String
}");
...
//add resolvers
...
在服务器配置上:
services
.AddGraphQLServer()
.TryAddSchemaInterceptor<TenantSchemaInterceptor>()
.AddFiltering();
但是,这还不够,因为没有应用过滤器。
询问:
{
persons (where: { name: {eq: "Joao" }}){
name
}
}
结果:
{
"data": {
"persons": [
{
"name": "Joao"
},
{
"name": "Liliana"
}
]
}
}
我能做些什么来解决这个问题吗?
谢谢大家
解决方案
对模式优先的过滤器支持在版本 12 中提供。然后您甚至不必指定所有内容,因为我们将提供模式构建指令。
type Query {
persons: [Person] @filtering
}
type Person {
name: String
}
您还可以控制可以提供哪些过滤器操作。本周我们将进行第一次预览。
推荐阅读
- javascript - 用于触发器数据库的猫鼬钩子或快速中间件?
- angular - 使 Angular 7 应用程序 seo 兼容
- css - css中的反转框边框如何使这个像素完美
- angular - 如何避免在任何 IE 版本上加载 Angular?
- excel - 从公式中获取的 Excel 值无法在 SUM 中计算
- python - 如何找到表标签中的“a”标签的下一个兄弟?
- c# - func?.Invoke() 是什么意思?
- xml - 将 JavaScript 添加到 XSL 文件,或者我可以使用什么 xsl 函数
- java - 使用ParameterizedPreparedStatementSetter时如何避免在Spring JdbcTemplate batchUpdate方法中添加元素?
- php - 查找元素存在于第一个数组中,而不存在于动态数组的第二个中