I am not the only one who does not know how to use types Datetimewith GraphQL-Ruby: https://github.com/rmosolgo/graphql-ruby-demo/issues/27 , as you can see, there are 18 people like me.
Datetime
How can I use datetime for some such fields?
Types::PlayerType = GraphQL::ObjectType.define do name 'Player' field :id, !types.ID field :birth_date, types.Datetime #or what? field :death_date, !types.Datetime #or what? field :note, types.String end
Maybe I need to use this ( https://github.com/howtographql/graphql-ruby/blob/master/app/graphql/types/date_time_type.rb ):
date_time_type.rb
Types::DateTimeType = GraphQL::ScalarType.define do name 'DateTime' coerce_input ->(value, _ctx) { Time.zone.parse(value) } coerce_result ->(value, _ctx) { value.utc.iso8601 } end
Can anyone explain this better?
A type declaration should work correctly. Keep in mind that the DateTimeType you inserted is located in the Types module. Use it like this:
Types::PlayerType = GraphQL::ObjectType.define do name 'Player' field :id, !types.ID field :birth_date, Types::DateTimeType field :death_date, Types::DateTimeType field :note, types.String end
, 5 (Int, String, Float, Boolean, ID), , , types.DateTime.
types.DateTime
DateTimeType, , (date_time_type.rb), :
field :birth_date, Types::DateTimeType
Not sure if I have a more detailed explanation, but I got it for work by pasting the code above to define my own scalar DateTimeType:
DateTimeType
DateTimeType = GraphQL::ScalarType.define do name 'DateTime' coerce_input ->(value, _ctx) { Time.zone.parse(value) } coerce_result ->(value, _ctx) { value.utc.iso8601 } end MyType = ::GraphQL::ObjectType.define do name 'MyType' field :when, type: !DateTimeType end
Source: https://habr.com/ru/post/1691303/More articles:How to get Java 9 ModuleReference for an unnamed module - javaOptimize capture lists - closuresImplement STL functions in a variation template - c ++Variable types in C and that track this - cWhy isn't this move constructor called temporary? - c ++Generating an xml file attribute value by counting a specific string using LINQ 2 XML? - c #Is paddings access safe in a structure or pool? - cConnection was rejected when using WebSocet to connect to the server - javaUnable to create global hello program with Stack due to bytestring flag - lt-0_10_4 - haskellPython bike cutting - pythonAll Articles