【问题标题】:Type mismatch on variable and argument (Int / Int)变量和参数的类型不匹配 (Int / Int)
【发布时间】:2021-04-06 13:34:36
【问题描述】:

鉴于以下 GraphQL 请求和变量:

请求:

query accounts($filter:AccountFilter, $first_:String, $skip_:Int) {
  accounts(filter: $filter, first: $first_, skip: $skip_) {
    id
  }
}

变量:

{
  "filter": {},
  "first_": "3",
  "skip_": 0
}

注意:我在first_skip_ 变量名称中添加了下划线,以帮助将它们与参数firstskip 区分开来。

我收到以下错误:

"Type mismatch on variable $first_ and argument first (String / Int)"

"Type mismatch on variable $skip_ and argument skip (Int / Int)"

我故意创建的第一个错误是为了进行健全性检查。变量中的值应该是"first": 3, 而不是"first": "3",。第二个错误我不明白为什么我得到它。 IntInt 类型如何不匹配?当我正确传递3 并将String 更改为Int 时,first 变量/参数错误会重新报告相同的错误(Int / Int)

我做错了什么?

后端规格: Ruby on Rails

参数说明:

"""
Interface for the Account model
"""
type Account {
  friendlyId: String!
  id: ID!
  locations: [Location!]!
  name: String!
  participants: [User!]!
  primaryLocation: Location!
  primarySiteContact: User!
  siteContacts: [User!]!
}

input AccountFilter {
  OR: [AccountFilter!]
}

type Query {
  """
  Details for an Account
  """
  accountDetails(id: ID): Account

  """
  A list of Accounts
  """
  accounts(filter: AccountFilter, first: Int, skip: Int): [Account!]
}

【问题讨论】:

  • 在哪里?什么环境/语言? ... 此查询的 BE 规格/参数类型?
  • 你能分享你的架构吗?
  • @xadm 抱歉,我没有后端会出现差异,我以为我推断出firstskip 应该是Ints。
  • @JosephHall,我添加了相关的架构部分(参见第二次编辑)。这是专有的,所以我只包括了我认为有必要知道的内容。如果你需要别的东西,请告诉我。感谢您的帮助!
  • 它可能是语言/实现(解析器)特定的问题,因为 gql 类型/参数看起来不错

标签: graphql syntax-error type-mismatch


【解决方案1】:

因此,这是(曾经)用于 Ruby 的 graphql 的一个已知问题。这个问题似乎有一个 PR 和可用的修复程序,但即使在更新我的 graphql gem 之后我仍然遇到这个问题。

您可以在此处查看问题: https://github.com/rmosolgo/graphql-ruby/issues/2784

该帖子中包含的对我有用的修复在这里:

def self.type_from_ast(*args)
  type = super
  type == GraphQL::Types::Int ? type.to_graphql : type
end

【讨论】:

    猜你喜欢
    • 2018-03-16
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多