![](/img/trans.png)
[英]Why GraphQL-Ruby does not understand dynamically generated schema definitions?
[英]why does graphql-ruby's boolean type not return false on null value
在graphql-ruby存儲庫中,布爾類型如下所示:
GraphQL::BOOLEAN_TYPE = GraphQL::ScalarType.define do
name "Boolean"
description "Represents `true` or `false` values."
coerce_input ->(value, _ctx) { (value == true || value == false) ? value : nil }
coerce_result ->(value, _ctx) { !!value }
default_scalar true
end
但是,當我查詢從數據庫返回nil的布爾字段時,我得到null。
在我的筆記類型中,我直接將graphql字段與數據庫中的boolean屬性耦合。
field :is_public, types.Boolean
有人可以解釋一下,也許想出一種不涉及更改所有字段的解決方案?
每當給出非布爾值時,默認的GraphQL::BOOLEAN_TYPE
返回nil,如下所示: https : //github.com/rmosolgo/graphql-ruby/blob/7f7e97cc2902046d485adcb6e8e6a5eb462b3faf/spec/graphql/boolean_type_spec.rb
所以這里可能發生的是, types.Boolean
仍映射到舊的GraphQL::BOOLEAN_TYPE
而不使用新的覆蓋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.