graphql-engine/server/src-lib/Network/URI/Extended.hs
Auke Booij 5edca3a5c2 server: add tshow :: Show a => a -> Text, including hlint hint (#142)
GitOrigin-RevId: 627a55533831b51aa0d01f8a8d95e3d013744dc5
2020-12-08 12:38:31 +00:00

30 lines
723 B
Haskell

{-# OPTIONS_GHC -fno-warn-orphans #-}
module Network.URI.Extended
( module Network.URI
)
where
import Data.Aeson
import Data.Aeson.Types
import Data.Hashable
import Hasura.Prelude
import Network.URI
import qualified Data.Text as T
instance {-# INCOHERENT #-} FromJSON URI where
parseJSON (String uri) = do
let mUrl = parseURI $ T.unpack uri
onNothing mUrl (fail "not a valid URI")
parseJSON _ = fail "not a valid URI"
instance {-# INCOHERENT #-} ToJSON URI where
toJSON = String . tshow
instance {-# INCOHERENT #-} ToJSONKey URI where
toJSONKey = toJSONKeyText tshow
instance Hashable URI where
hashWithSalt i = hashWithSalt i . tshow