【问题标题】:GraphQL Unknown argument "limit" on field even though it was defined in the schema字段上的 GraphQL 未知参数“限制”,即使它是在模式中定义的
【发布时间】:2020-11-28 13:10:31
【问题描述】:

当我尝试在字段上传递参数参数时,我被卡住了。我收到此错误消息: "message": "Unknown argument \"limit\" on field \"User.followers\"."

query {
  getUser(username: "johnsmith") { # <= this argument is ok
    username
    followers(limit: 10) { # <= but this one is not
      users {
        username
      }
    }
  }
}

但我认为我在架构中正确定义了该参数。

  type Query {
    getUser(username: ID!): User!
    followers(limit: Int!): Followers!
  }
Query: {
    getUser: (_, { username }) => getUser(username),
  },
  User: {
    followers: ({ username }, args) => getAllFollowers(username, args)
  }
}

然而,我的 Graphql Playground 自动生成的文档提到了“limit”参数:

followers(
limit: Int!
): Followers!

我错过了什么吗?感谢您的帮助。

【问题讨论】:

    标签: graphql apollo-server


    【解决方案1】:

    Query 类型上的 followers 字段与 User 类型上的 followers 字段不同。

    【讨论】:

      猜你喜欢
      • 2017-02-03
      • 2020-05-18
      • 2017-09-06
      • 2019-06-06
      • 2019-03-28
      • 2020-02-18
      • 1970-01-01
      • 2020-01-10
      • 2019-10-01
      相关资源
      最近更新 更多