In the graphql-ruby repo the Boolean type looks like this:
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
But when i query a boolean field which returns nil from database i get null.
In my note type i have directly coupled a graphql field with my boolean attribute in the database.
field :is_public, types.Boolean
Can someone please explain this and maybe come up with a solution that does not involve changing all the fields?
The default GraphQL::BOOLEAN_TYPE
returns nil whenever a non boolean value is given as seen here: https://github.com/rmosolgo/graphql-ruby/blob/7f7e97cc2902046d485adcb6e8e6a5eb462b3faf/spec/graphql/boolean_type_spec.rb
So what might be happening here is that types.Boolean
is still mapped to the old GraphQL::BOOLEAN_TYPE
and not using your new override.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.