mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
85cda65261
[NDAT-490]: https://hasurahq.atlassian.net/browse/NDAT-490?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ [NDAT-491]: https://hasurahq.atlassian.net/browse/NDAT-491?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ [NDAT-468]: https://hasurahq.atlassian.net/browse/NDAT-468?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7487 Co-authored-by: Solomon <24038+solomon-b@users.noreply.github.com> GitOrigin-RevId: ba679fc69df4b669fc7936cd359b8268e8e1a23a
53 lines
1.8 KiB
Haskell
53 lines
1.8 KiB
Haskell
-- | 'get_feature_flag' Metadata API action. Given a feature flag
|
|
-- identifier, it returns the value of the flag and its description.
|
|
module Hasura.RQL.DDL.FeatureFlag
|
|
( -- * Get Feature Flag
|
|
GetFeatureFlag (..),
|
|
runGetFeatureFlag,
|
|
)
|
|
where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
--------------------------------------------------------------------------------
|
|
import Data.Aeson (FromJSON, (.:), (.=))
|
|
import Data.Aeson qualified as Aeson
|
|
import Data.HashMap.Strict qualified as HashMap
|
|
import Hasura.Base.Error qualified as Error
|
|
import Hasura.EncJSON (EncJSON)
|
|
import Hasura.EncJSON qualified as EncJSON
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Init.FeatureFlag qualified as FeatureFlag
|
|
import Hasura.Server.Types qualified as Types
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
newtype GetFeatureFlag = GetFeatureFlag {gfgIdentifier :: Text}
|
|
|
|
instance FromJSON GetFeatureFlag where
|
|
parseJSON = Aeson.withObject "GetFeatureFlag" \o -> do
|
|
gfgIdentifier <- o .: "identifier"
|
|
pure $ GetFeatureFlag {..}
|
|
|
|
runGetFeatureFlag ::
|
|
( MonadError Error.QErr m,
|
|
Types.HasServerConfigCtx m,
|
|
MonadIO m
|
|
) =>
|
|
GetFeatureFlag ->
|
|
m EncJSON
|
|
runGetFeatureFlag GetFeatureFlag {..} = do
|
|
checkFeatureFlag <- Types._sccCheckFeatureFlag <$> Types.askServerConfigCtx
|
|
let flagM = HashMap.lookup gfgIdentifier $ FeatureFlag.getFeatureFlags $ FeatureFlag.featureFlags
|
|
case flagM of
|
|
Nothing -> Error.throw400 Error.NotFound $ "Feature Flag '" <> gfgIdentifier <> "' not found"
|
|
Just flag -> do
|
|
flagValue <- liftIO $ checkFeatureFlag flag
|
|
pure $
|
|
EncJSON.encJFromJValue $
|
|
Aeson.object
|
|
[ "identifier" .= gfgIdentifier,
|
|
"value" .= flagValue,
|
|
"description" .= FeatureFlag.ffDescription flag
|
|
]
|