mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
975b022b29
This reduces the usage of "utils" modules in the parsers code, especially those that are simply re-exported from elsewhere, to facilitate extracting the parsers code into its own library. It mostly inlines the imports that are re-exported from `Hasura.Prelude` and `Data.Parser.JSONPath`. It also removes references to `Data.*.Extended` modules. When necessary, it re-implements the functionality (which is typically trivial). It does not tackle all external dependencies. I observed the following that will take more work: - `Data.GADT.Compare.Extended` - `Data.Text.Extended` - `Hasura.Base.Error` - `Hasura.RQL.Types.Common` - `Hasura.Server.Utils` PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4964 GitOrigin-RevId: 54ad3c1b7a31f13e34340ebe9fcc36d0ad57b8bd
36 lines
1.1 KiB
Haskell
36 lines
1.1 KiB
Haskell
module Hasura.GraphQL.Parser.Names
|
|
( MkTypename (..),
|
|
mkTypename,
|
|
withTypenameCustomization,
|
|
HasName (..),
|
|
)
|
|
where
|
|
|
|
import Control.Lens
|
|
import Control.Monad.Reader (MonadReader, asks, local)
|
|
import Data.Has
|
|
import Data.Monoid
|
|
import Language.GraphQL.Draft.Syntax (Name (..))
|
|
import Prelude
|
|
|
|
class HasName a where
|
|
getName :: a -> Name
|
|
|
|
instance HasName Name where
|
|
getName = id
|
|
|
|
-- | Type name customization
|
|
newtype MkTypename = MkTypename {runMkTypename :: Name -> Name}
|
|
deriving (Semigroup, 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 = local . set hasLens
|
|
|
|
-- | Apply the type name customization function from the current environment.
|
|
mkTypename :: (MonadReader r m, Has MkTypename r) => Name -> m Name
|
|
mkTypename name =
|
|
($ name) . runMkTypename <$> asks getter
|