繁体   English   中英

使用带有模式优先方法的 hotchocolate 过滤器

[英]Using hotchocolate's filters with schema first approach

我正在使用模式拦截器来配置我的模式。 这是一个多租户的应用程序,所以我根据租户的配置来构建架构。 我将该配置映射到 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
}

您还可以控制可以提供哪些过滤器操作。 本周我们将进行第一次预览。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM