【发布时间】:2020-08-06 05:53:27
【问题描述】:
我在 Ruby on Rails 中使用 graphql-client 来使用星期一的 api,所以问题是,当我尝试查询某些内容时,api 中的名称带有下划线
query {
items (limit: 50) {
column_values {
id
value
}
}
}
我收到类似GraphQL::Client::ValidationError (Field 'column_values' doesn't exist on type 'Item') 的错误,在阅读了一些网站(例如Graphql Field doesn't exist on type)后,它说您必须将下划线更改为驼峰式。所以我做到了
query {
items (limit: 50) {
columnValues {
id
value
}
}
}
我没有收到来自 ruby 的错误,但在发送查询后,来自服务器(星期一 api)的响应是相同的,但使用驼峰式 Field 'columnValues' doesn't exist on type 'Item'。
阅读其他网站后,似乎 under_score 和 camelCase 是 GraphQL 的常见问题。
【问题讨论】:
-
查询在星期一的操场上测试了吗?如果它有效,则在 graphql-client github 上创建一个问题 - 下划线名称在 graphql 规范中有效
-
是的,我确实在星期一的操场上测试了查询,如果我更改为 camelCase 不起作用,它与 under_score 一起工作得很好。问题是当我在 ruby 中解析
Query = SWAPI::Client.parse时,只有当我使用 camelCase 但它会与星期一的 api 发生冲突时才让我继续。我在 github 上看到了一个类似 github.com/github/graphql-client/issues/212 的问题,从去年开始没有答案。
标签: ruby-on-rails ruby graphql