mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
7739f8e4a0
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5996 GitOrigin-RevId: 2ed36898aa0286618f3dafe3513ef4e01c58aaba
117 lines
4.1 KiB
Haskell
117 lines
4.1 KiB
Haskell
-- |
|
|
-- Definitions for schema building configuration.
|
|
module Hasura.GraphQL.Schema.Options
|
|
( SchemaOptions (..),
|
|
StringifyNumbers (..),
|
|
DangerouslyCollapseBooleans (..),
|
|
InferFunctionPermissions (..),
|
|
RemoteSchemaPermissions (..),
|
|
OptimizePermissionFilters (..),
|
|
IncludeUpdateManyFields (..),
|
|
BigQueryStringNumericInput (..),
|
|
)
|
|
where
|
|
|
|
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), withBool)
|
|
import Hasura.Prelude
|
|
|
|
-- | The record of options required to build the schema. This includes options
|
|
-- that can be enabled with 'Hasura.Server.Types.ExperimentalFeature' flags.
|
|
data SchemaOptions = SchemaOptions
|
|
{ soStringifyNumbers :: StringifyNumbers,
|
|
soDangerousBooleanCollapse :: DangerouslyCollapseBooleans,
|
|
soInferFunctionPermissions :: InferFunctionPermissions,
|
|
soOptimizePermissionFilters :: OptimizePermissionFilters,
|
|
soIncludeUpdateManyFields :: IncludeUpdateManyFields,
|
|
soBigQueryStringNumericInput :: BigQueryStringNumericInput
|
|
}
|
|
|
|
-- | Should we represent numbers in our responses as numbers, or strings?
|
|
-- Some backends can return numbers that exceed the bounds of JSON's own
|
|
-- number type. In these cases, we can use stringified versions of these
|
|
-- numbers to avoid this problem.
|
|
data StringifyNumbers
|
|
= StringifyNumbers
|
|
| Don'tStringifyNumbers
|
|
deriving (Eq, Show)
|
|
|
|
-- | Should we include `TABLE_updates` fields in schemas
|
|
-- This is a toggle so that users can opt-in, and so that we can rename
|
|
-- any tables that this may conflict with if needed
|
|
data IncludeUpdateManyFields
|
|
= IncludeUpdateManyFields
|
|
| DontIncludeUpdateManyFields
|
|
deriving (Eq, Show)
|
|
|
|
-- | Should Boolean fields be collapsed to 'True' when a null value is
|
|
-- given? This was the behaviour of Hasura V1, and is now discouraged.
|
|
data DangerouslyCollapseBooleans
|
|
= DangerouslyCollapseBooleans
|
|
| Don'tDangerouslyCollapseBooleans
|
|
deriving (Eq, Show)
|
|
|
|
instance FromJSON DangerouslyCollapseBooleans where
|
|
parseJSON =
|
|
withBool "DangerouslyCollapseBooleans" $
|
|
pure . \case
|
|
True -> DangerouslyCollapseBooleans
|
|
False -> Don'tDangerouslyCollapseBooleans
|
|
|
|
instance ToJSON DangerouslyCollapseBooleans where
|
|
toJSON = \case
|
|
DangerouslyCollapseBooleans -> Bool True
|
|
Don'tDangerouslyCollapseBooleans -> Bool False
|
|
|
|
-- | Should we infer function permissions? If this flag is set to
|
|
-- 'InferFunctionPermissions', we may fail to build expression parsers
|
|
-- in 'buildQueryAndSubscriptionFields' for users with unrecognised roles.
|
|
data InferFunctionPermissions
|
|
= InferFunctionPermissions
|
|
| Don'tInferFunctionPermissions
|
|
deriving (Eq, Show)
|
|
|
|
instance FromJSON InferFunctionPermissions where
|
|
parseJSON =
|
|
withBool "InferFunctionPermissions" $
|
|
pure . \case
|
|
True -> InferFunctionPermissions
|
|
False -> Don'tInferFunctionPermissions
|
|
|
|
instance ToJSON InferFunctionPermissions where
|
|
toJSON = \case
|
|
InferFunctionPermissions -> Bool True
|
|
Don'tInferFunctionPermissions -> Bool False
|
|
|
|
-- | Should we enable remote schema permissions? If so, these permissions will
|
|
-- influence 'Hasura.GraphQL.Schema.buildGQLContext'.
|
|
data RemoteSchemaPermissions
|
|
= EnableRemoteSchemaPermissions
|
|
| DisableRemoteSchemaPermissions
|
|
deriving (Eq, Show)
|
|
|
|
instance FromJSON RemoteSchemaPermissions where
|
|
parseJSON =
|
|
withBool "RemoteSchemaPermissions" $
|
|
pure . \case
|
|
True -> EnableRemoteSchemaPermissions
|
|
False -> DisableRemoteSchemaPermissions
|
|
|
|
instance ToJSON RemoteSchemaPermissions where
|
|
toJSON = \case
|
|
EnableRemoteSchemaPermissions -> Bool True
|
|
DisableRemoteSchemaPermissions -> Bool False
|
|
|
|
-- | Should we attempt to deduplicate permission filters? This flag is used in
|
|
-- 'Hasura.GraphQL.Schema.Select.relationshipField' to determine whether
|
|
-- certain row-level permission filters can be dropped in certain cases.
|
|
data OptimizePermissionFilters
|
|
= OptimizePermissionFilters
|
|
| Don'tOptimizePermissionFilters
|
|
deriving (Eq, Show)
|
|
|
|
-- | Should we enable string-accepting scalar parsers for BigQuery sources
|
|
data BigQueryStringNumericInput
|
|
= EnableBigQueryStringNumericInput
|
|
| DisableBigQueryStringNumericInput
|
|
deriving (Eq, Show)
|