GraphTypes
A Collection of Types for GraphQL.
Installation
Install from RubyGems by adding it to your Gemfile
, then bundling.
gem 'graph_types'
$ bundle install
Types:
DateTimeType
Declaration:
DummyType = GraphQL::ObjectType.define do
name "Dummy"
field :name, !types.String
field :createdAt, !GraphTypes::DateTimeType, property: :created_at
end
Search:
birthday {
formatted(strftime: "%Y-%m-%d")
}
Result:
"birthday": {
"formatted": "2018-01-22"
}
MoneyType
Declaration:
DummyType = GraphQL::ObjectType.define do
name "Dummy"
field :name, !types.String
field :price, !GraphTypes::MoneyType, property: :price
end
Search:
amount {
cents
formatted(delimiter: ".", separator: ",", unit: "R$ ")
}
Result:
"amount": {
"cents": 10000,
"formatted": "R$ 100,00"
}
Interfaces:
TimestampableInterface:
Declaration:
DummyType = GraphQL::ObjectType.define do
name "Dummy"
interfaces [TimestampableInterface]
end
Search:
dummy {
createdAt {
formatted(strftime: "%FT%T%Z")
}
updatedAt {
formatted(strftime: "%FT%T%Z")
}
}
Result:
"dummy": {
"createdAt": "2018-01-11T17:36:07BRST",
"updatedAt": "2018-01-11T17:36:07BRST"
}