{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Morpheus.Types.ID
( ID(..)
) where
import Data.Morpheus.Kind (SCALAR)
import Data.Morpheus.Types.GQLScalar (GQLScalar (..))
import Data.Morpheus.Types.GQLType (GQLType (KIND))
import Data.Morpheus.Types.Internal.Value (ScalarValue (..))
import Data.Text (Text, pack)
import GHC.Generics (Generic)
newtype ID = ID
{ unpackID :: Text
} deriving (Show, Generic)
instance GQLType ID where
type KIND ID = SCALAR
instance GQLScalar ID where
parseValue (Int x) = return (ID $ pack $ show x)
parseValue (String x) = return (ID x)
parseValue _ = Left ""
serialize (ID x) = String x