From 53f9d0d323d273ac533912a4e04bf48400a4ca07 Mon Sep 17 00:00:00 2001 From: Saku Laesvuori Date: Fri, 19 Jan 2024 13:25:30 +0200 Subject: [PATCH] Add morpheus instances for Scope --- core/src/Datarekisteri/Core/Types.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/Datarekisteri/Core/Types.hs b/core/src/Datarekisteri/Core/Types.hs index 5d04874..885e4e8 100644 --- a/core/src/Datarekisteri/Core/Types.hs +++ b/core/src/Datarekisteri/Core/Types.hs @@ -83,7 +83,18 @@ data Scope = OwnProfile | Tokens UserID | Members | Applications - deriving (Show, Eq, Ord, Read) + deriving (Show, Eq, Ord, Read, Generic) + +instance DecodeScalar Scope where + decodeScalar (String s) = maybe (Left $ "invalid Scope: \"" <> s <> "\"") Right $ readMaybe (toString s) + decodeScalar _ = Left "Invalid type for Scope, should be string" + +instance EncodeScalar Scope where + encodeScalar = String . show + +instance GQLType Scope where type KIND Scope = SCALAR +instance ToJSON Scope where toJSON = scalarToJSON +instance FromJSON Scope where parseJSON = scalarFromJSON <=< parseJSON data Permission = None | ReadOnly