mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
c980af1b8f
This moves `MkTypename` and `NamingCase` into their own modules, with the intent of reducing the scope of the schema parsers code, and trying to reduce imports of large modules when small ones will do. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4978 GitOrigin-RevId: 19541257fe010035390f6183a4eaa37bae0d3ca1
32 lines
1.1 KiB
Haskell
32 lines
1.1 KiB
Haskell
module Hasura.GraphQL.Schema.NamingCase
|
|
( NamingCase (..),
|
|
parseNamingConventionFromText,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson qualified as Aeson
|
|
import Hasura.Incremental (Cacheable)
|
|
import Hasura.Prelude
|
|
|
|
-- | Represents the different possible type cases for fields and types, i.e.
|
|
-- @HasuraCase@ and @GraphqlCase@ (@CamelCase@ fields and @PascalCase@ types).
|
|
data NamingCase = HasuraCase | GraphqlCase
|
|
deriving (Eq, Show, Generic)
|
|
|
|
instance Cacheable NamingCase
|
|
|
|
instance Aeson.ToJSON NamingCase where
|
|
toJSON HasuraCase = Aeson.String "hasura-default"
|
|
toJSON GraphqlCase = Aeson.String "graphql-default"
|
|
|
|
instance Aeson.FromJSON NamingCase where
|
|
parseJSON = Aeson.withText "NamingCase" $ \s -> case parseNamingConventionFromText s of
|
|
(Right nc) -> pure nc
|
|
(Left err) -> fail err
|
|
|
|
-- Used for both the environment variable and JSON.
|
|
parseNamingConventionFromText :: Text -> Either String NamingCase
|
|
parseNamingConventionFromText "hasura-default" = Right HasuraCase
|
|
parseNamingConventionFromText "graphql-default" = Right GraphqlCase
|
|
parseNamingConventionFromText _ = Left "naming_convention can either be \"hasura-default\" or \"graphql-default\""
|