2022-07-12 17:00:15 +03:00
|
|
|
module Hasura.GraphQL.Schema.NamingCase
|
2023-05-17 17:02:09 +03:00
|
|
|
( isGraphqlCase,
|
2023-04-12 13:26:09 +03:00
|
|
|
hasNamingConventionChanged,
|
2022-07-12 17:00:15 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2023-04-12 13:26:09 +03:00
|
|
|
import Data.HashSet qualified as Set
|
2022-07-12 17:00:15 +03:00
|
|
|
import Hasura.Prelude
|
2023-05-17 17:02:09 +03:00
|
|
|
import Hasura.RQL.Types.NamingCase
|
2023-04-12 13:26:09 +03:00
|
|
|
import Hasura.Server.Types (ExperimentalFeature (..))
|
2022-07-12 17:00:15 +03:00
|
|
|
|
2022-07-19 09:55:42 +03:00
|
|
|
isGraphqlCase :: NamingCase -> Bool
|
|
|
|
isGraphqlCase GraphqlCase = True
|
|
|
|
isGraphqlCase _ = False
|
2023-04-12 13:26:09 +03:00
|
|
|
|
|
|
|
-- | Check if naming convention has changed
|
|
|
|
-- The value of naming convention depends on whether the naming convention is enabled
|
|
|
|
-- in experimental features and what the default naming convention
|
|
|
|
-- (`HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION`) is hence use both these values to
|
|
|
|
-- decide if naming convention has changed
|
|
|
|
hasNamingConventionChanged :: (Set.HashSet ExperimentalFeature, NamingCase) -> (Set.HashSet ExperimentalFeature, NamingCase) -> Bool
|
|
|
|
hasNamingConventionChanged (prevExperimentalFeatures, prevDefaultNamingCase) (currExperimentalFeatures, currDefaultNamingCase) =
|
|
|
|
case ((EFNamingConventions `elem` prevExperimentalFeatures, prevDefaultNamingCase), (EFNamingConventions `elem` currExperimentalFeatures, currDefaultNamingCase)) of
|
|
|
|
-- naming convention has been enabled, and the default naming convention is not
|
|
|
|
-- HasuraCase then the naming convention has changed
|
|
|
|
((False, _), (True, GraphqlCase)) -> True
|
|
|
|
-- naming is enabled but the default naming convention changes, then the naming
|
|
|
|
-- convention has changed
|
|
|
|
((True, GraphqlCase), (True, HasuraCase)) -> True
|
|
|
|
((True, HasuraCase), (True, GraphqlCase)) -> True
|
|
|
|
-- graphql-case naming convention has been disabled, then the naming convention
|
|
|
|
-- changes
|
|
|
|
((True, GraphqlCase), (False, _)) -> True
|
|
|
|
_ -> False
|