Skip to content

Commit

Permalink
server: fix the FromJSON instance of ExperimentalFeature
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 4d3c296
  • Loading branch information
codingkarthik authored and hasura-bot committed Mar 16, 2021
1 parent e4b669e commit d1a2fab
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions server/src-lib/Hasura/Server/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module Hasura.Server.Types where
import Hasura.Prelude

import Data.Aeson
import Data.Aeson.Casing
import Data.Aeson.TH

import qualified Data.HashSet as Set
import qualified Database.PG.Query as Q
Expand Down Expand Up @@ -42,14 +40,17 @@ data ExperimentalFeature
= EFInheritedRoles
deriving (Show, Eq, Generic)

$(deriveFromJSON (defaultOptions { constructorTagModifier = snakeCase . drop 2})
''ExperimentalFeature)
instance Hashable ExperimentalFeature

-- TODO: when there are more than one constuctors in `ExperimentalFeature`, we should
-- derive the `ToJSON` instance like we do it for the `FromJSON` instance. Doing it
-- with a single data constructor messes up the `ToJSON` instance which is why it's
-- manually implemented here
-- auto derive the JSON instances. Doing it with a single data constructor messes
-- up the JSON instances which is why it's manually implemented here

instance FromJSON ExperimentalFeature where
parseJSON = withText "ExperimentalFeature" $ \case
"inherited_roles" -> pure EFInheritedRoles
_ -> fail "ExperimentalFeature can only be one of these value: inherited_roles "

instance ToJSON ExperimentalFeature where
toJSON = \case
EFInheritedRoles -> "inherited_roles"
Expand Down

0 comments on commit d1a2fab

Please sign in to comment.