graphql - 变量和参数的类型不匹配 (Int / Int)
问题描述
给定以下 GraphQL 请求和变量:
要求:
query accounts($filter:AccountFilter, $first_:String, $skip_:Int) {
accounts(filter: $filter, first: $first_, skip: $skip_) {
id
}
}
变量:
{
"filter": {},
"first_": "3",
"skip_": 0
}
注意:first_
我在和变量名称中添加了下划线,skip_
以帮助将它们与参数first
和. 区分开来skip
。
我收到以下错误:
"Type mismatch on variable $first_ and argument first (String / Int)"
"Type mismatch on variable $skip_ and argument skip (Int / Int)"
我故意创建的第一个错误是为了进行健全性检查。变量中的值应该是"first": 3,
而不是"first": "3",
。第二个错误我不明白为什么我得到它。Int
和类型如何Int
不匹配?当我正确传递first
并更改为.(Int / Int)
3
String
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!]
}
解决方案
所以这是 Ruby 的 graphql 的一个已知问题。graphql
这个问题似乎有一个 PR 和可用的修复程序,但即使在更新我的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
推荐阅读
- javascript - 按名称获取 Map 中的值
- python - PyQt lineEdit on textEdited 信号值在函数调用后丢失
- javascript - 如何在代码中使用变量?
- android - 如何使按钮不能滚动
- node.js - webpack 4 优化 dev 和 prod 构建之间的不同块命名
- javascript - facebook ip 一天访问千次触发js错误(TypeError: Illegal invocation)
- python - 将两个图像与 PIL 和 numpy 组合后的质量损失
- php - 使用 woocommerce 更新变体订单价格
- assembly - 某个字符在字符串中出现的次数(汇编emu8086)
- css - 按类强制 Bootstrap 4 断点(用于预览)