Creating Your Own Scalar Types

Scalar types form the leaves of your input and output trees. You’re already pretty familiar with a number of scalar types that we’ve used as inputs and outputs. 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 users of Absinthe.

Building your own scalar types can be handy, too. Let’s say, for instance, that we’d like to support a :date scalar type that supports users providing dates in a nice, easy-to-use format, automatically giving us Date structs that are easier for us to use in Elixir.

If we wanted to filter our menu item list by the date ...

Get Craft GraphQL APIs in Elixir with Absinthe now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.