2022-07-14 20:57:28 +03:00
|
|
|
-- |
|
|
|
|
-- Definitions for schema building configuration.
|
|
|
|
module Hasura.GraphQL.Schema.Options
|
|
|
|
( SchemaOptions (..),
|
|
|
|
StringifyNumbers (..),
|
|
|
|
DangerouslyCollapseBooleans (..),
|
|
|
|
InferFunctionPermissions (..),
|
|
|
|
RemoteSchemaPermissions (..),
|
|
|
|
OptimizePermissionFilters (..),
|
2022-10-25 16:20:19 +03:00
|
|
|
IncludeAggregationPredicates (..),
|
2022-11-04 16:08:40 +03:00
|
|
|
IncludeStreamFields (..),
|
2022-09-26 16:24:01 +03:00
|
|
|
IncludeUpdateManyFields (..),
|
2022-09-30 16:24:32 +03:00
|
|
|
BigQueryStringNumericInput (..),
|
2022-07-14 20:57:28 +03:00
|
|
|
)
|
|
|
|
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,
|
2022-09-26 16:24:01 +03:00
|
|
|
soOptimizePermissionFilters :: OptimizePermissionFilters,
|
2022-09-30 16:24:32 +03:00
|
|
|
soIncludeUpdateManyFields :: IncludeUpdateManyFields,
|
2022-10-25 16:20:19 +03:00
|
|
|
soIncludeAggregationPredicates :: IncludeAggregationPredicates,
|
2022-11-04 16:08:40 +03:00
|
|
|
soIncludeStreamFields :: IncludeStreamFields,
|
2022-09-30 16:24:32 +03:00
|
|
|
soBigQueryStringNumericInput :: BigQueryStringNumericInput
|
2022-07-14 20:57:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
-- | 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)
|
|
|
|
|
2022-09-26 16:24:01 +03:00
|
|
|
-- | 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
|
2022-11-04 16:08:40 +03:00
|
|
|
| Don'tIncludeUpdateManyFields
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
|
|
|
-- | Should we include `TABLE_stream` 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 IncludeStreamFields
|
|
|
|
= IncludeStreamFields
|
|
|
|
| Don'tIncludeStreamFields
|
2022-09-26 16:24:01 +03:00
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2022-10-25 16:20:19 +03:00
|
|
|
-- | Should we include aggregation functions in where clauses?
|
|
|
|
-- Because this has the potential to cause naming conflicts in graphql schema
|
|
|
|
-- types, this flag allows users to toggle the feature off if it an upgrade breaks
|
|
|
|
-- their setup.
|
|
|
|
data IncludeAggregationPredicates
|
|
|
|
= IncludeAggregationPredicates
|
|
|
|
| Don'tIncludeAggregationPredicates
|
|
|
|
|
2022-07-14 20:57:28 +03:00
|
|
|
-- | 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)
|
|
|
|
|
2022-08-26 07:37:35 +03:00
|
|
|
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
|
|
|
|
|
2022-07-14 20:57:28 +03:00
|
|
|
-- | 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)
|
2022-09-30 16:24:32 +03:00
|
|
|
|
|
|
|
-- | Should we enable string-accepting scalar parsers for BigQuery sources
|
|
|
|
data BigQueryStringNumericInput
|
|
|
|
= EnableBigQueryStringNumericInput
|
|
|
|
| DisableBigQueryStringNumericInput
|
|
|
|
deriving (Eq, Show)
|