Creating Your Own Scalar Types
Learn how to create user defined scalar types.
We'll cover the following
User defined scalar types
Scalar types form the leaves of our input and output trees. Absinthe’s built-in scalar types, from :integer
to :string
and :id
, all have a firm grounding in the GraphQL specification. These types are not special cases but are built using the same schema tools provided to Absinthe users.
Building your own scalar types can be handy, too. Let’s say we’d like to support a :date
scalar type that supports users providing dates in a nice, easy-to-use format. This would automatically give us Date structs that are easier to use in Elixir.
If we want to filter our menu item list by the date prior to which the menu item was added, it would be nice to support a nicely formatted date as an argument. This can be seen below:
Get hands-on with 1400+ tech skills courses.