【问题标题】:normal graphql queries causing errors导致错误的正常 graphql 查询
【发布时间】:2019-09-19 16:22:37
【问题描述】:

我已经搜索了一段时间,并从 SO 社区获得了很多帮助。但是,我的项目设置似乎不允许正常查询,例如排序、限制、过滤或其他。

我正在查询一个自定义中间件/drupal 站点。

抛出错误的示例:

{
  umdHub(limit: 5) {
    articles {
      data {
        id
        title
        subtitle
        body
        summary
      }
    }
  }
}

{
  umdHub(
    sort: {
      fields: [authorship_date___time]
      order: ASC
    }
  ) {
    articles {
      data {
        id
        title
        subtitle
        body
        summary
        authorship_date {
          formatted_short
          unix
          unix_int
          formatted_long
          formatted_short
          time
        }
      }
    }
  }
}

http://localhost:8000/___graphql 中的所有返回错误如:

{
  "errors": [
    {
      "message": "Unknown argument \"limit\" on field \"umdHub\" of type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 10
        }
      ]
    }
  ]
}

我该如何解决这些问题?

【问题讨论】:

  • 你能发布你的解析器吗?

标签: reactjs graphql gatsby


【解决方案1】:

那是因为您在字段 umdHub 中没有参数 limit。 为了解决这个问题,让我们在 Query 类型的 umdHub 字段上检查您的架构,并添加 limit 参数,然后重新启动您的服务器。

示例:

type Query {
  umdHub(limit: Int, sort: SortInput) { // <-- Add this
   articles
  }
}

【讨论】:

  • 抱歉,有些文档我不知道。我在上面发布的实现略有不同,不确定它是否对其他人有帮助,但您的回答可能
【解决方案2】:

原来这是这样做的方法:

{
  umdHub {
    articles (page: { limit: 5 }) {
      data {
        id
        title
        subtitle
        body
        summary
        hero_image {
          url_1200_630
        }
        authorship_date {
          formatted_short
          unix
          unix_int
          formatted_long
          formatted_short
          time
        }
        slug
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2017-08-14
    • 1970-01-01
    • 2016-02-14
    • 2018-09-17
    • 1970-01-01
    相关资源
    最近更新 更多