2018-11-23 16:02:46 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
|
|
|
module Network.URI.Extended
|
2020-12-08 15:37:35 +03:00
|
|
|
( module Network.URI
|
2018-11-23 16:02:46 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson
|
|
|
|
import Data.Aeson.Types
|
|
|
|
import Data.Hashable
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Network.URI
|
|
|
|
|
2020-05-13 15:33:16 +03:00
|
|
|
import qualified Data.Text as T
|
2018-11-23 16:02:46 +03:00
|
|
|
|
|
|
|
instance {-# INCOHERENT #-} FromJSON URI where
|
|
|
|
parseJSON (String uri) = do
|
|
|
|
let mUrl = parseURI $ T.unpack uri
|
2020-10-28 19:40:33 +03:00
|
|
|
onNothing mUrl (fail "not a valid URI")
|
2018-11-23 16:02:46 +03:00
|
|
|
parseJSON _ = fail "not a valid URI"
|
|
|
|
|
|
|
|
instance {-# INCOHERENT #-} ToJSON URI where
|
2020-12-08 15:37:35 +03:00
|
|
|
toJSON = String . tshow
|
2018-11-23 16:02:46 +03:00
|
|
|
|
|
|
|
instance {-# INCOHERENT #-} ToJSONKey URI where
|
2020-12-08 15:37:35 +03:00
|
|
|
toJSONKey = toJSONKeyText tshow
|
2018-11-23 16:02:46 +03:00
|
|
|
|
|
|
|
instance Hashable URI where
|
2020-12-08 15:37:35 +03:00
|
|
|
hashWithSalt i = hashWithSalt i . tshow
|