问题描述
我正在使用架构拦截器来配置我的架构。这是一个多租户应用程序,所以我根据租户的配置构建架构。我将该配置映射到 SDL 语言(架构优先方法),然后将其添加到架构构建器 (schemaBuilder.AddDocumentFromString(...)
)。
如文档 (here) 所述,“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
}
您还可以控制可以提供哪些过滤器操作。我们将在本周发布第一个预览版。