ryannhg / graphql / GraphQL.Scalar.Id

Custom scalars

Using the GraphQL.Decode.scalar and GraphQL.Encode.scalar functions, you can define Elm modules like this one in your own codebase for any custom scalars you need.

Because the ID scalar is built-in to the GraphQL specification, we provide this one for you by default. Your custom scalars will also include a decoder / encode function so they are easy to reuse across your application!


type Id

Represents a GraphQL ID scalar value.

fromString : String -> Id

Use a String value to create a new ID:

import GraphQL.Scalar.Id exposing (Id)

id : Id
id =
    GraphQL.Scalar.Id.fromString "12a4bf"

fromInt : Basics.Int -> Id

Use a Int value to create a new ID:

import GraphQL.Scalar.Id exposing (Id)

id : Id
id =
    GraphQL.Scalar.Id.fromInt 123

toString : Id -> String

Convert an existing ID to a String value:

import GraphQL.Scalar.Id exposing (Id)

messageToUser : String
messageToUser =
    "Your ID is: " ++ GraphQL.Scalar.Id.toString userId