簡體   English   中英

為什么graphql-ruby的布爾類型在null值上不返回false

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM