View Source Absinthe.Type.Scalar (absinthe v1.7.5)
Represents a primitive value.
GraphQL responses take the form of a hierarchical tree; the leaves on these trees are scalars.
Also see Absinthe.Type.Object
.
built-in-scalars
Built-In Scalars
The following built-in scalar types are defined:
:boolean
- Representstrue
orfalse
. See the GraphQL Specification.:float
- Represents signed double-precision fractional values as specified by IEEE 754. See the GraphQL Specification.:id
- Represents a unique identifier, often used to refetch an object or as key for a cache. The ID type is serialized in the same way as a String; however, it is not intended to be human-readable. See the GraphQL Specification.:integer
- Represents non-fractional signed whole numeric value. By default it is not compliant with the GraphQl Specification, it can represent values between-(2^53 - 1)
and2^53 - 1
as specified by IEEE 754. To use the GraphQl compliant Int, representing values between-2^31
and2^31 - 1
, in your schemause Absinthe.Schema, use_spec_compliant_int_scalar: true
.:string
- Represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. See the GraphQL Specification.
built-in-custom-types
Built-in custom types
Note that absinthe includes a few generic extra scalar types in Absinthe.Type.Custom
,
these are not part of the GraphQL spec thus they must be explicitly imported.
Consider using them before implementing a custom type.
example
Example
Supporting ISO8601 week date format, using Timex:
scalar :iso_week_date do
description "ISO8601 week date (ex: 2022-W42-2)"
parse &Timex.parse(&1, "{YYYY}-W{Wiso}-{WDmon}")
serialize &Timex.format!(&1, "{YYYY}-W{Wiso}-{WDmon}")
end
Link to this section Summary
Functions
Callback implementation for c:Absinthe.Introspection.TypeKind.kind/0
.
Link to this section Types
@type t() :: %Absinthe.Type.Scalar{ __private__: Keyword.t(), __reference__: Absinthe.Type.Reference.t(), definition: module(), description: binary(), identifier: atom(), name: binary(), open_ended: term(), parse: term(), serialize: term() }
A defined scalar type.
Note new scalars should be defined using Absinthe.Schema.Notation.scalar
.
:name
- The name of scalar. Should be a TitleCasedbinary
. Set Automatically byAbsinthe.Schema.Notation.scalar
.:description
- A nice description for introspection.:serialize
- A function used to convert a value to a form suitable for JSON serialization:parse
- A function used to convert the raw, incoming form of a scalar to the canonical internal format.
The :__private__
and :__reference__
keys are for internal use.
@type value_t() :: any()
The internal, canonical representation of a scalar value
Link to this section Functions
Callback implementation for c:Absinthe.Introspection.TypeKind.kind/0
.