【问题标题】:How to handle where clause in GraphQL Schema如何处理 GraphQL Schema 中的 where 子句
【发布时间】:2023-01-05 21:21:13
【问题描述】:

我是 GraphQL 的新手,使用 Flask 和 GraphQL 创建 API 服务器, 在处理 GraphQL 请求中的“where”子句时遇到一些问题。

基本的请求和响应工作正常。请找到我设计的架构的简短 sn-p

***SCHEMA***
        type data{
                edges:[data_edges]
        
            }
            type QueryCustom{
                data:data
            }
           type Query {
                query:QueryCustom
            }

下面提到的基本请求(没有 where 子句)在这个模式下工作正常

**REQUEST:** 
query{ 
     query{
          data{
           edges{....}

但是当我使用 where 子句执行请求时出错

query dataClosingSoon($month: Long) {
    data(
        where: {LastModifiedDate: { CALENDAR_MONTH: { value: { eq: $month } } }}
               ) {
        edges { ....... }

错误

{
    "errors": [
        {
            "locations": [
                {
                    "column": 40,
                    "line": 1
                }
            ],
            "message": "Unknown type 'Long'."
        },
        {
            "locations": [
                {
                    "column": 9,
                    "line": 5
                }
            ],
            "message": "Unknown argument 'where' on field 'QueryCustom.data'."
        }
    ]
}

我需要了解如何处理 where 条件和

【问题讨论】:

    标签: python flask graphql


    【解决方案1】:

    GraphQL 不是 SQL。您不能在 GraphQL 查询中使用 WHERELIKE 等 SQL 子句。

    您需要查看架构以检查如何过滤查询。这些过滤器是在架构中预定义的。您不能为 GraphQL 查询创建自定义过滤器(至少在基本意义上)。

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 2017-05-16
      • 2018-11-03
      • 2019-05-30
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      相关资源
      最近更新 更多