Scalar Types

Description

Represents a primitive value in GraphQL. GraphQL responses take the form of a hierarchical tree; the leaves on these trees are GraphQL scalars.

Absinthe Macro

scalar

Examples

In an Absinthe schema, defining a custom scalar type by providing functions to parse input and serialize results:

 scalar ​:datetime​, ​name:​ ​"​​DateTime"​ ​do
  serialize &DateTime.to_iso8601/1
  parse &parse_datetime/1
 end

Built-in Scalars

A number of built-in scalar types are part of the specification and are predefined for you by Absinthe.

Boolean (Built-in)

Description

The Boolean scalar type represents true or false.

Absinthe Identifier

:boolean

Float (Built-in)

Description

The Float scalar type represents signed double-precision fractional values as specified by IEEE 754. Response formats that support an appropriate double-precision number type should use that type to represent this scalar.

Absinthe Identifier

:float

ID (Built-in)

Description

The ID scalar type represents a unique identifier, often used to refetch an object or as the 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. While it is often numeric, it should always serialize as a String.

Absinthe Identifier

:id

Int (Built-in)

Description

The Int scalar type represents a signed 32-bit numeric non-fractional value. Response formats that support a 32-bit integer or a number type should use that type to represent this scalar.

Absinthe Identifier

:integer

String (Built-in)

Description

Represents textual data as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.

Absinthe Identifier

:string

Absinthe Scalars

Absinthe ships with a number of custom scalars predefined for convenience. They are found in Absinthe.Type.Custom and include:

  • :datetime
  • :naive_datetime
  • :date
  • :time
  • :decimal (when the decimal package is a dependency)

To use these scalar types, add the following to your Absinthe schema:

 import_types Absinthe.Type.Custom
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.39.60