module Hasura.GraphQL.Schema.Typename
  ( MkTypename (..),
    withTypenameCustomization,
  )
where

import Control.Lens (set)
import Data.Has (Has (..))
import Data.Monoid (Endo (..))
import Hasura.Prelude
import Language.GraphQL.Draft.Syntax (Name)

-- | Type name customization
newtype MkTypename = MkTypename {MkTypename -> Name -> Name
runMkTypename :: Name -> Name}
  deriving (NonEmpty MkTypename -> MkTypename
MkTypename -> MkTypename -> MkTypename
(MkTypename -> MkTypename -> MkTypename)
-> (NonEmpty MkTypename -> MkTypename)
-> (forall b. Integral b => b -> MkTypename -> MkTypename)
-> Semigroup MkTypename
forall b. Integral b => b -> MkTypename -> MkTypename
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: MkTypename -> MkTypename -> MkTypename
<> :: MkTypename -> MkTypename -> MkTypename
$csconcat :: NonEmpty MkTypename -> MkTypename
sconcat :: NonEmpty MkTypename -> MkTypename
$cstimes :: forall b. Integral b => b -> MkTypename -> MkTypename
stimes :: forall b. Integral b => b -> MkTypename -> MkTypename
Semigroup, Semigroup MkTypename
MkTypename
Semigroup MkTypename
-> MkTypename
-> (MkTypename -> MkTypename -> MkTypename)
-> ([MkTypename] -> MkTypename)
-> Monoid MkTypename
[MkTypename] -> MkTypename
MkTypename -> MkTypename -> MkTypename
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: MkTypename
mempty :: MkTypename
$cmappend :: MkTypename -> MkTypename -> MkTypename
mappend :: MkTypename -> MkTypename -> MkTypename
$cmconcat :: [MkTypename] -> MkTypename
mconcat :: [MkTypename] -> MkTypename
Monoid) via (Endo Name)

-- | Inject a new @MkTypename@ customization function into the environment.
-- This can be used by schema-building code (with @MonadBuildSchema@ constraint) to ensure
-- the correct type name customizations are applied.
withTypenameCustomization :: forall m r a. (MonadReader r m, Has MkTypename r) => MkTypename -> m a -> m a
withTypenameCustomization :: forall (m :: * -> *) r a.
(MonadReader r m, Has MkTypename r) =>
MkTypename -> m a -> m a
withTypenameCustomization = (r -> r) -> m a -> m a
forall a. (r -> r) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((r -> r) -> m a -> m a)
-> (MkTypename -> r -> r) -> MkTypename -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter r r MkTypename MkTypename -> MkTypename -> r -> r
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter r r MkTypename MkTypename
forall a t. Has a t => Lens t a
Lens r MkTypename
hasLens